#include "sylar/sylar.h"#include "sylar/ds/array.h"static sylar::Logger::ptr g_logger = SYLAR_LOG_ROOT();struct PidVid {PidVid(uint32_t p = 0, uint32_t v = 0):pid(p), vid(v) {}uint32_t pid;uint32_t vid;bool operator<(const PidVid& o) const {return memcmp(this, &o, sizeof(o)) < 0;}};void gen() {sylar::ds::Array<int> tmp;std::vector<int> vs;for(int i = 0; i < 10000; ++i) {int v = rand();tmp.insert(v);vs.push_back(v);SYLAR_ASSERT(tmp.isSorted());}std::ofstream ofs("./array.data");tmp.writeTo(ofs);for(auto& i : vs) {auto idx = tmp.exists(i);SYLAR_ASSERT(idx >= 0);tmp.erase(idx);SYLAR_ASSERT(tmp.isSorted());}SYLAR_ASSERT(tmp.size() == 0);}void test() {for(int i = 0; i < 10000; ++i) {SYLAR_LOG_INFO(g_logger) << "i=" << i;std::ifstream ifs("./array.data");sylar::ds::Array<int> tmp;if(!tmp.readFrom(ifs)) {SYLAR_LOG_INFO(g_logger) << "error";}SYLAR_ASSERT(tmp.isSorted());if(i % 100 == 0) {SYLAR_LOG_INFO(g_logger) << "over..." << (i + 1);}}}int main(int argc, char** argv) {gen();test();return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。