1 Star 1 Fork 2

NathanJoy/cppframe

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_array.cc 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
NathanJoy 提交于 2021-02-01 13:41 +08:00 . update
#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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/nathanjoy/cppframe.git
git@gitee.com:nathanjoy/cppframe.git
nathanjoy
cppframe
cppframe
master

搜索帮助