memgraph/tests/concurrent/dynamic_bitset.cpp

48 lines
1.3 KiB
C++
Raw Normal View History

2016-08-03 00:05:10 +08:00
#include "common.h"
2016-12-22 22:51:16 +08:00
constexpr size_t THREADS_NO = std::min(max_no_threads, 8);
constexpr size_t op_per_thread = 1e5;
constexpr size_t bit_part_len = 2;
constexpr size_t no_slots = 1e4;
constexpr size_t key_range = no_slots * THREADS_NO * bit_part_len;
2016-08-03 00:05:10 +08:00
constexpr size_t no_sets_per_clear = 2;
2016-12-22 22:51:16 +08:00
// TODO: document the test
2016-08-03 00:05:10 +08:00
int main()
{
DynamicBitset<> db;
2016-12-22 22:51:16 +08:00
2016-08-03 00:05:10 +08:00
auto seted =
collect_set(run<std::vector<bool>>(THREADS_NO, [&](auto index) {
2016-12-22 22:51:16 +08:00
auto rand = rand_gen(no_slots);
2016-08-03 00:05:10 +08:00
auto clear_op = rand_gen_bool(no_sets_per_clear);
std::vector<bool> set(key_range);
2016-12-22 22:51:16 +08:00
for (size_t i = 0; i < op_per_thread; i++)
{
2016-08-03 00:05:10 +08:00
size_t num =
rand() * THREADS_NO * bit_part_len + index * bit_part_len;
2016-12-22 22:51:16 +08:00
if (clear_op())
{
2016-08-03 00:05:10 +08:00
db.clear(num, bit_part_len);
2016-12-22 22:51:16 +08:00
for (int j = 0; j < bit_part_len; j++)
{
2016-08-03 00:05:10 +08:00
set[num + j] = false;
}
2016-12-22 22:51:16 +08:00
}
else
{
2016-08-03 00:05:10 +08:00
db.set(num, bit_part_len);
2016-12-22 22:51:16 +08:00
for (int j = 0; j < bit_part_len; j++)
2016-08-03 00:05:10 +08:00
set[num + j] = true;
}
}
return set;
}));
check_set(db, seted);
}