27 #define BM_NONSTANDARD_EXTENTIONS
85 #if defined(BMSSE2OPT) || defined(BMSSE42OPT) || defined(BMAVX2OPT) || defined(BMAVX512OPT) || defined(__ARM_NEON__)
93 #include <unordered_map>
106 std::unordered_map<void*, std::string> g_alloc_trace_map;
113 static inline size_t na_ = 0;
114 static inline size_t nf_ = 0;
120 stack_str.reserve(2048);
130 std::cerr <<
"ERROR Failed allocation!" << endl;
136 g_alloc_trace_map.emplace(p, std::move(stack_str));
149 printf(
"Block memory deallocation ERROR! n = %i (expected %i)\n", (
int)
n, (
int)*p);
154 g_alloc_trace_map.erase(p);
165 static inline size_t na_ = 0;
166 static inline size_t nf_ = 0;
172 stack_str.reserve(2048);
178 assert(
sizeof(
size_t) ==
sizeof(
void*));
179 void* p =
::malloc((
n+1) *
sizeof(
void*));
182 std::cerr <<
"ERROR! Failed allocation!" << endl;
185 size_t* s = (
size_t*) p;
189 g_alloc_trace_map.emplace(p, std::move(stack_str));
200 size_t* s = (
size_t*) p;
204 printf(
"Ptr memory deallocation ERROR!\n");
211 g_alloc_trace_map.erase(s);
259 template<
typename BV>
261 typename BV::size_type left,
typename BV::size_type right)
265 bool is_left(0), is_right(0);
267 is_left = bv.test(left - 1);
268 if ((is_left ==
false) && (right <
bm::id_max - 1))
269 is_right = bv.test(right + 1);
270 if (is_left ==
false && is_right ==
false)
272 typename BV::size_type
cnt = bv.count_range(left, right);
273 if (
cnt == (1 + right - left))
286 for (; en1.
valid(); ++en1)
302 std::cerr <<
"Difference detected at: position="
303 << i1 <<
" nb=" << nb1
304 <<
"[" << ii1 <<
", " << jj1 <<
"]"
305 " other position = " << i2 <<
307 <<
"[" << ii2 <<
", " << jj2 <<
"]"
309 std::cerr <<
" en1.count()=" << en1.
count() <<
" en2.count()=" << en2.
count()
318 bool eq = bv1.equal(bv2);
321 cerr <<
"EQ (1-2) discrepancy! " << endl;
324 int cmp = bv1.compare(bv2);
327 cerr <<
"Compare (1-2) discrepancy! " <<
cmp << endl;
330 cmp = bv2.compare(bv1);
333 cerr <<
"Compare (2-1) discrepancy! " <<
cmp << endl;
337 cout <<
"Detailed compare OK (no difference)." << endl;
343 bool detailed =
true);
350 std::vector<bm::id_t>* vp = (std::vector<bm::id_t>*)handle_ptr;
351 vp->push_back(bit_idx);
373 typename BV::size_type left, right,
next, i_end;
374 bool non_empty = bv.find_range(left, right);
382 auto drange = right - left;
390 cout <<
"... VisitorAllRangeTest() step=" << step << endl;
393 for (
auto i = left;
i <= right;
i+=step)
403 bool eq = bv2.
equal(bv_control);
406 next = bv.get_next(
i);
433 cout <<
"\r" <<
i <<
" / " << right << flush;
442 for (; left <= right; left+=step, --right)
452 bool eq = bv2.
equal(bv_control);
455 next = bv.get_next(left);
469 delta = i_end - left;
478 cout <<
"\r" << left <<
" / " << right << flush;
493 unsigned r = (unsigned(rand()) << 16u) |
unsigned(rand());
497 template<
typename BV>
501 typename BV::size_type pos, pos_c, pos_l;
502 f = bv1.find_first_mismatch(bv2, pos);
513 bool f2 = bv1.find_first_mismatch(bv2, pos_l, pos);
518 f2 = bv1.find_first_mismatch(bv2, pos_l, pos-1);
522 bool cf = bv_x.
find(pos_c);
526 f = bv2.find_first_mismatch(bv1, pos);
537 unsigned fill_factor)
545 unsigned n_id = (
max -
min) / 100;
546 printf(
"random filling : %i\n", n_id);
547 for (
i = 0;
i < n_id;
i++)
557 printf(
"fill_factor random filling : factor = %i\n", fill_factor);
559 for(
i = 0;
i < fill_factor;
i++)
561 unsigned k = unsigned(rand()) % 10;
566 unsigned start =
min + (
max -
min) / (fill_factor * k);
577 unsigned end = start + (
max - start) / (fill_factor *2);
593 unsigned r = unsigned(rand()) % 8;
597 unsigned inc = unsigned(rand()) % 3;
599 unsigned end2 = start + (unsigned)rand() % 1000;
627 unsigned c = unsigned(rand()) % 15;
630 for(; start < end; ++start)
656 unsigned fill_factor,
660 while(fill_factor==0)
662 fill_factor=(unsigned)rand()%10;
666 cout <<
"Intervals filling. Factor="
667 << fill_factor << endl << endl;
670 unsigned factor = 70 * fill_factor;
677 len = unsigned(rand()) % factor;
680 }
while (end >=
max);
685 assert(all_one_range == set_flag);
686 bool any_one = bvect_full.
any_range(
i, end - 1);
687 assert(any_one == set_flag);
690 assert(is_int == is_int_c);
699 for (j =
i; j < end; ++j)
721 len *= unsigned(rand()) % (factor * 10);
728 for(
unsigned k=0; k < 1000 &&
i <
max; k+=3,
i+=3)
753 unsigned fill_factor)
766 unsigned bit_idx = unsigned(rand()) %
range;
769 std::cout <<
"Bit_idx=" << bit_idx << endl;
777 unsigned fill_factor)
780 unsigned diap =
max -
min;
796 for (
unsigned i = 0;
i <
count; ++
i)
798 unsigned bn = unsigned(rand()) %
count;
808 cout <<
"Ok" << endl;
821 unsigned step = (unsigned)rand() % 4;
822 if (step < 2) ++step;
823 for (
unsigned i = 0;
i <
max;
i+=step)
829 cout <<
"Ok" << endl;
857 cout <<
"Random filling: method - FillSets - factor(0)" << endl;
862 cout <<
"Random filling: method - FillSets - factor(random)" << endl;
863 factor = (unsigned)rand()%3;
868 cout <<
"Random filling: method - Set-Clear Intervals - factor(random)" << endl;
869 factor = (unsigned)rand()%10;
873 cout <<
"Random filling: method - FillRandom - factor(random)" << endl;
874 factor = (unsigned)rand()%3;
878 cout <<
"Random set one bit" << endl;
882 cout <<
"Regular pattern filling" << endl;
886 cout <<
"Random filling: method - Set Intervals - factor(random)" << endl;
887 factor = (unsigned)rand()%10;
893 if (optimize && (method <= 1))
903 std::cout << bv.
count() <<
": ";
905 for (; en.
valid(); ++en)
906 std::cout << *en <<
", ";
907 std::cout << std::endl;
918 for (; en.
valid(); ++en)
921 unsigned new_v = v + shift;
944 for (; en.
valid(); ++en)
949 unsigned new_v = v + 1;
974 for (; en.
valid(); ++en)
992 bool check_reverse=
false)
1003 check_reverse =
false;
1027 cout <<
"Error: Optimize failed to compute max_serialize_mem" << endl;
1035 cout <<
"Error:Optimize failed to compute max_serialize_mem" << endl;
1049 cout <<
"Serialization override detected!" << endl;
1056 cout << slen1 <<
" " << slen2 << endl;
1057 int res = bv1.
compare(*bv_target);
1060 cout <<
"---------------------------------- " << endl;
1061 cout <<
"bv1.count()=" << bv1.
count() << endl;
1063 cout <<
"---------------------------------- " << endl;
1064 cout <<
"bv_target.count()=" << bv_target->
count() << endl;
1068 cout <<
"First diff=" << bv_target->
get_first() << endl;
1069 cout <<
"set_ASSIGN 1 failed!" << endl;
1072 cout <<
"Deserialization ASSIGN into bv1 OK" << endl;
1077 if (*bv_tmp2 != bv1)
1079 cout <<
"Deserialize NOT equal to Operation deserialize!" << endl;
1086 cout <<
"Operation deserialization... " << op << endl;
1089 cout <<
"OK" << endl;
1093 bvect bv_agg, bv_agg2;
1098 const bvect* agg_list[10];
1099 const bvect* agg_list2[10];
1102 agg_list2[0] = &bv2;
1105 bool agg_check =
false;
1116 bv_merge1.
merge(bv_merge2);
1118 if (bv_merge1 != bvc)
1120 cerr <<
"Merge(OR) check error!" << endl;
1129 cerr <<
"1. OR 2-way check error!" << endl;
1136 cerr <<
"2. OR 2-way check error!" << endl;
1156 cerr <<
"1. XOR 2-way check error!" << endl;
1157 cerr <<
"Run detailed check (1)..." << endl;
1164 cerr <<
"Reverse XOR 2-way check failed too!" << endl;
1167 cerr <<
"Run detailed check (2)..." << endl;
1176 cerr <<
"2. XOR 2-way check error!" << endl;
1186 if (bv_agg != bv_agg2)
1188 cerr <<
"Error: Aggregator AND - AND-SUB(0) comparison failed!" << endl;
1206 cerr <<
"1. AND 2-way check error!" << endl;
1216 cerr <<
"1.1 AND 2-way check error!" << endl;
1224 cerr <<
"2. AND 2-way check error!" << endl;
1231 cerr <<
"2.1 AND 2-way check error!" << endl;
1244 cerr <<
"Error: Aggregator Horz-AND-SUB comparison failed!" << endl;
1261 cerr <<
"1. SUB 2-way check error!" << endl;
1268 cerr <<
"2. SUB 2-way check error!" << endl;
1277 if (bvt.
compare(*bv_target) != 0)
1279 cout <<
"Direct Serial operation comparison failed!" << endl;
1282 if (agg_check && bvt.
compare(bv_agg) != 0)
1284 cerr <<
"Error: Aggregator operation comparison failed!" << endl;
1333 cout <<
"Reverse check... " << endl;
1339 cout <<
"set_ASSIGN failed 2! " << endl;
1344 cout <<
"set_ASSIGN failed 2-1! " << endl;
1347 cout <<
"Deserialization assign to bv_tmp2 OK" << endl;
1348 unsigned count_rev =
1350 if (
count != count_rev)
1368 cout <<
"Operation=" << op << endl;
1370 cout <<
"Serialization operation reverse check failed"
1371 <<
" count = " <<
count
1372 <<
" count rev= " << count_rev
1374 cout <<
"See bvector dumps: err1.bv, err2.bv" << endl;
1391 unsigned predicted_count,
1395 bv_target->
clear(
true);
1400 cout <<
"Serialization operation count..." << endl;
1408 cout <<
"Serialization operation count OK." << endl;
1412 cout <<
"Serialization operation. " << endl;
1417 scount2 = bv_target->
count();
1418 if (predicted_count != scount2 || scount1 != scount2)
1420 cout <<
"Serialization count != predicted" << endl
1421 <<
" predicted=" << predicted_count
1422 <<
" scount1=" << scount1
1423 <<
" scount2=" << scount2
1426 cout << endl <<
"target:" << endl;
1428 cout << endl << endl <<
"Reference" << endl;
1429 if (op_combine ==
set_OR)
1432 if (bv1 != *bv_target)
1434 cout <<
"Comparison OR error!" << endl;
1436 cout <<
"OR operation count=" << bv1.
count() << endl;
1454 scount3 = bv_target2.
count();
1455 assert(scount3 == scount2);
1457 bool eq = bv_target->
equal(bv_target2);
1460 cout <<
"OK" << endl;
1475 if ((
i % 31) == 0 && (
i != 0))
1487 printf(
"[%i:]", *
buf++ & 1);
1489 for (
unsigned i = 1;
i <
len; ++
i)
1491 printf(
"%i,", *
buf++);
1502 for (
unsigned i = 0;
i <
len; ++
i)
1508 cout <<
"Bit comparison failed. " <<
"Bit N=" <<
i << endl;
1518 bool found = gapv.
get_last(&glast);
1519 if (!found && last_bit != -1)
1521 cout <<
"Gap last search failed. " <<
"Bit=" << last_bit << endl;
1526 if (found && last_bit == -1)
1528 cout <<
"Gap last search ok but should failed. " <<
"Bit=" <<
1534 if (last_bit != (
int)glast)
1536 if (!found && last_bit == -1)
1540 cout <<
"Gap last search discrepancy:" <<
" found Bit=" <<
1541 glast <<
" last=" << last_bit << endl;
1565 unsigned prev = *en;
1566 for (++en; en.
valid(); ++en)
1589 cout <<
"CheckIntervals error. " <<
"bm count=" << cnt0
1590 <<
" Control = " << cnt1 << endl;
1598 unsigned* block_count_arr=0)
1600 unsigned cnt1 = vect.count_range(left, right, block_count_arr);
1602 for (
unsigned i = left;
i <= right; ++
i)
1611 cout <<
"Bitcount range failed!" <<
"left=" << left
1612 <<
" right=" << right << endl
1613 <<
"count_range()=" << cnt1
1614 <<
" check=" << cnt2;
1619 template<
typename T>
1625 typename T::enumerator en = bv.get_enumerator(from);
1627 typename T::enumerator en2 = bv.get_enumerator(from);
1629 en2.skip_to_rank(
rank);
1632 for (; en.valid(); ++en)
1646 cerr <<
"FindRank enumerator::skip() failed: "
1647 <<
"pos=" << pos <<
" skip()pos=" << pos2
1662 bvect bv_cp(bv, from, to);
1663 bvect bv_cp2(bv, to, from);
1670 int res = bv_control.
compare(bv_cp);
1676 bvect bv_cp3(bv, from, to);
1678 cerr <<
"Error: bvector<>::range_copy() failed. from=" << from <<
" to=" << to << endl;
1680 cerr <<
" range copy from=" << f1 <<
" to=" << l1 << endl;
1682 cerr <<
" control from=" << f2 <<
" to=" << l2 << endl;
1686 int res2 = bv_control.
compare(bv_cp2);
1692 cerr <<
"Error: reversed bvector<>::range_copy() failed. from=" << from <<
" to=" << to << endl;
1694 cerr <<
" range copy from=" << f1 <<
" to=" << l1 << endl;
1696 cerr <<
" control from=" << f2 <<
" to=" << l2 << endl;
1702 if (found1 != found2)
1704 cerr <<
"Error: Dynamic range integrity check." << endl;
1709 if (f1 != f2 || l1 != l2)
1711 cerr <<
"Error: bvector<>::range_copy() failed (dynamic range check). from=" << from <<
" to=" << to << endl;
1712 cerr <<
" range copy from=" << f1 <<
" to=" << l1 << endl;
1713 cerr <<
" control from=" << f2 <<
" to=" << l2 << endl;
1726 unsigned cnt1 = vect.count_range(left, right);
1729 typename T::enumerator en = vect.get_enumerator(left);
1730 for (; en.valid(); ++en)
1738 cout <<
"2. Bitcount range failed!" <<
"left=" << left
1739 <<
" right=" << right << endl
1740 <<
"count_range()=" << cnt1
1741 <<
" check=" << cnt2;
1757 unsigned cnt_to_r = vect.count_to(right, bc_arr);
1758 cnt1 = vect.count_range(left, right, bc_arr);
1759 unsigned cnt_to_l = left ? vect.count_to(left - 1, bc_arr) : 0;
1760 cnt2 = cnt_to_r - cnt_to_l;
1763 cout <<
"Bitcount range TO failed!" <<
" left=" << left
1764 <<
" right=" << right << endl
1765 <<
" count_range()=" << cnt1
1766 <<
" check=" << cnt2;
1773 cerr <<
"Impossible count_range detected!" << endl;
1774 cerr <<
" range = " <<
range << endl;
1775 cerr <<
" cnt1 = " << cnt1 << endl;
1776 cerr <<
" left = " << left << endl;
1777 cerr <<
" right = " << right << endl;
1778 cnt1 = vect.count_range(left, right, bc_arr);
1779 cerr <<
" cnt1 = " << cnt1 << endl;
1788 bool rf = vect.find_rank(cnt1, left, pos);
1789 bool rf1 = vect.find_rank(cnt1, left, pos1, bc_arr);
1792 cerr <<
"1. find_rank() failed!" <<
" left=" << left
1793 <<
" right=" << right
1794 <<
" count_range()=" << cnt1
1797 <<
" range=" <<
range
1801 bool rf2 =
FindRank(vect, cnt1, left, pos2);
1804 cerr <<
"Debug FindRank failed!" << endl;
1808 cerr <<
" rank=" << pos2 << endl;
1811 cerr <<
"detailed bug search..." << endl;
1812 for (
unsigned k = 1; k <= cnt1; ++k)
1814 rf = vect.find_rank(k, left, pos);
1815 rf2 =
FindRank(vect, k, left, pos2);
1816 if (rf != rf2 || pos != pos2)
1818 rf = vect.find_rank(k, left, pos);
1820 cerr <<
"Failed for rank=" << k << endl;
1821 cerr << rf <<
" " << rf2 << endl;
1822 cerr <<
"pos = " << pos <<
" pos2 = " << pos2 << endl;
1835 bv1.build_rs_index(bc_arr2.get());
1837 bool rf3 = bv1.select(cnt1, pos3, *bc_arr2);
1845 bool rf2 =
FindRank(vect, cnt1, left, pos2);
1851 rf = vect.find_rank(cnt1, left, pos);
1852 cout <<
"2. find_rank() check failed! \n" <<
"left=" << left
1853 <<
" right=" << right
1854 <<
" count_range()=" << cnt1
1856 <<
" rank = " << pos2
1869 unsigned bit_prev = word & 1;
1871 for (
unsigned i = 1;
i < 32; ++
i)
1873 unsigned bit = word & 1;
1874 count += bit ^ bit_prev;
1892 cout <<
"Second vector - invalid enumerator at:" << *en1;
1897 cout <<
"Discrepancy at bit position: " << *en1;
1898 cout <<
" second vector is at:" << *en2;
1904 cout <<
"Detailed check OK" << endl;
1909 const bvect &bvect_full,
1912 cout <<
"Detailed check" << endl;
1922 bool bv_f_flag = bvect_full.
get_bit(
i) != 0;
1924 if (bv_m_flag != bv_f_flag)
1926 printf(
"Bit %u is non conformant. vect_min=%i vect_full=%i\n",
1927 i, (
int)bv_m_flag, (
int)bv_f_flag);
1934 printf(
"\n detailed check ok.\n");
1946 cerr <<
"Enumerators FSM comparison failed" << endl;
1959 for (; en.
valid(); ++en)
1971 cout <<
" ... IntervalsCheck" << endl;
1976 typename BV::size_type intervals_c = 1;
1978 typename BV::enumerator en1 = bv.get_enumerator(0);
1979 typename BV::enumerator en2 = bv_inv.get_enumerator(0);
1983 typename BV::size_type from = *en1;
1984 typename BV::size_type to = *en2;
1987 bool all_one, any_one;
1988 bool is_int, is_int_c;
1991 all_one = bv.is_all_one_range(from, to-1);
1993 any_one = bv.any_range(from, to-1);
1997 assert(is_int == is_int_c);
2020 all_one = bv.is_all_one_range(from, to);
2022 any_one = bv.any_range(from, to);
2023 auto cnt = bv.count_range(from, to);
2034 assert(is_int == is_int_c);
2064 all_one = bv.is_all_one_range(from, to);
2066 any_one = bv.any_range(from, to);
2068 typename BV::size_type
cnt = bv.count_range(to, from);
2072 assert(is_int == is_int_c);
2097 all_one = bv.is_all_one_range(from, to);
2099 any_one = bv.any_range(from, to);
2101 typename BV::size_type
cnt = bv.count_range(from, to);
2105 assert(is_int == is_int_c);
2126 if (intervals != intervals_c)
2128 typename BV::size_type diff;
2129 diff =
std::max(intervals, intervals_c) -
std::min(intervals, intervals_c);
2132 cerr <<
"Intervals difference:" << diff << endl;
2141 typename BV::size_type from,
typename BV::size_type to)
2160 bv.set_range(
st,
end);
2166 template<
typename BV>
2170 cout <<
"..IntervalsEnumeratorCheck()" << flush;
2173 typename BV::size_type
f,
l, m;
2174 auto b = bv.find_range(
f,
l);
2186 cout <<
"1 " << flush;
2200 cout <<
"2 " << flush;
2215 cout <<
"3 " << flush;
2229 cout <<
"4 " << flush;
2243 cout <<
"5 " << flush;
2257 cout <<
"6 " << flush;
2284 cout <<
"\nVectors checking...bits to compare = " <<
size << endl;
2286 cout <<
"Bitcount summary : ";
2287 unsigned min_count = bvect_min.
bit_count();
2288 cout <<
" minvector count = " << min_count;
2291 cout <<
" fullvector re-count = " << full_count << endl;
2293 if (min_count != full_count)
2295 cout <<
"fullvector count = " <<
count << endl;
2296 cout <<
"Count comparison failed !!!!" << endl;
2305 bool any = bvect_full.
any();
2308 cout <<
"Anycheck failed!" << endl;
2320 assert(last_found1 == last_found2);
2334 cout <<
"Positive bits comparison..." << flush;
2335 unsigned nb_min = bvect_min.
get_first();
2336 unsigned nb_ful = bvect_full.
get_first();
2339 unsigned nb_en = *en;
2341 if (nb_min != nb_ful)
2343 cout <<
"!!!! First bit comparison failed. Full id = "
2344 << nb_ful <<
" Min id = " << nb_min
2347 bool bit_f = bvect_full.
get_bit(nb_ful);
2348 cout <<
"Full vector'd bit #" << nb_ful <<
"is:"
2351 bool bit_m = (bvect_min.
is_bit_true(nb_min) == 1);
2352 cout <<
"Min vector'd bit #" << nb_min <<
"is:"
2366 unsigned bit_count = 1;
2367 unsigned en_prev = nb_en;
2371 nb_min = bvect_min.
get_next(nb_min);
2382 if ((bit_count % 10 == 0) || (bit_count % 128 == 0))
2391 if (nb_en != nb_min)
2393 nb_ful = bvect_full.
get_next(en_prev);
2394 cout <<
"!!!!! next bit comparison failed. Full id = "
2395 << nb_ful <<
" Min id = " << nb_min
2396 <<
" Enumerator = " << nb_en
2405 }
while (en.
valid());
2406 if (bit_count != min_count)
2408 cout <<
" Bit count failed."
2409 <<
" min = " << min_count
2410 <<
" bit = " << bit_count
2416 cout <<
"OK" << endl;
2424 cout <<
"---------------------------- DynamicMatrixTest() test" << endl;
2432 unsigned*
r = matr.
row(1);
2433 for (
unsigned i = 0;
i < matr.
cols(); ++
i)
2441 unsigned*
r = matr.
row(3);
2442 for (
unsigned i = 0;
i < matr.
cols(); ++
i)
2449 const unsigned*
r = matr.
row(1);
2450 for (
unsigned i = 0;
i < matr.
cols(); ++
i)
2462 matr.
set(1, 1, 100);
2463 matr.
set(2, 2, 200);
2489 cout <<
"---------------------------- DynamicMatrixTest() test OK" << endl;
2495 cout <<
"---------------------------- RSIndexTest() test" << endl;
2551 bcount[
i] = 0; sub_count1[
i] = sub_count2[
i] = 0;
2557 sub_count1[255] = 0;
2558 sub_count2[0] = 1 << 16;
2559 sub_count2[255] = 1 << 16;
2570 auto tcnt = rsi.
count();
2622 assert(rbc == 65536+6 + 65536);
2627 auto nb = rsi.
find(1);
2638 nb = rsi.
find(65536);
2640 nb = rsi.
find(65536*2);
2642 nb = rsi.
find(65536*3);
2719 cout <<
"---------------------------- RSIndexTest() test OK" << endl;
2728 for (
unsigned i = 0;
i < 100000; ++
i)
2746 cout <<
"---------------------------- WordCmp test" << endl;
2748 for (
int i = 0;
i < 10000000; ++
i)
2750 unsigned w1 = unsigned(rand());
2751 unsigned w2 = unsigned(rand());
2756 printf(
"WordCmp failed !\n");
2760 res =
wordcmp0((
unsigned)0
U, (
unsigned)w2);
2761 res2 =
wordcmp((
unsigned)0
U, (
unsigned)w2);
2765 printf(
"WordCmp 0 test failed !\n");
2769 res =
wordcmp0((
unsigned)~0
U, (
unsigned)w2);
2770 res2 =
wordcmp((
unsigned)~0
U, (
unsigned)w2);
2774 printf(
"WordCmp ~0 test failed !\n");
2778 res =
wordcmp0((
unsigned)w2, (
unsigned)0);
2779 res2 =
wordcmp((
unsigned)w2, (
unsigned)0);
2783 printf(
"WordCmp 0-2 test failed !\n");
2789 cout <<
"Ok." << endl;
2796 cout <<
"---------------------------- CountChange test" << endl;
2798 #ifdef VECT_BLOCK_CHANGE
2829 blk[0] = blk[1] = blk[2] = blk[3] = 2;
2834 blk[4] = blk[5] = blk[6] = blk[7] = 2;
2866 cout <<
"Block change stress..." << endl;
2868 std::chrono::time_point<std::chrono::steady_clock> s;
2869 std::chrono::time_point<std::chrono::steady_clock>
f;
2870 s = std::chrono::steady_clock::now();
2873 unsigned k_max = (1u << 31) / 4;
2874 for (
unsigned k = 0; k <= k_max; ++k)
2882 if (k % 100000 == 0)
2884 f = std::chrono::steady_clock::now();
2886 auto d = std::chrono::duration <double, std::milli> (diff).count();
2889 cout <<
"\r" << k <<
" / " << k_max <<
" (" << d <<
"ms)" << flush;
2891 s = std::chrono::steady_clock::now();
2900 cout <<
"---------------------------- CountChange test OK" << endl;
2912 unsigned c_gc, c_bc;
2949 cout <<
"---------------------------- TestBlockCountXORChange() test" << endl;
3016 blk[0] = 1 | (1 << 1);
3060 xor_matches_vector_type;
3063 m_pairs_vector_type;
3064 xor_matches_vector_type xm_vect;
3065 m_pairs_vector_type pm_vect;
3069 xm_vect.push_back(xmd);
3073 assert(pm_vect.size()==0);
3076 assert(pm_vect.size()==1);
3079 assert(pm_vect[0].xor_d64 == 1ull);
3094 xm_vect.push_back(xmd);
3099 assert(pm_vect[0].ref_idx == 20);
3106 xm_vect.push_back(xmd);
3108 xm_vect.push_back(xmd);
3113 assert(pm_vect[0].ref_idx == 20);
3127 blk[
i] = blk_xor[
i] = 0;
3152 blk[0] = 1 | (1<<1) | (1<<2); blk_xor[0] = (1 << 1);
3161 blk[0] = 1; blk_xor[0] = 1;
3177 blk[0] = (1 << 10) | (1 << 12) | (1 << 14) | ( 1 << 16) | (1 << 18) | (1<<19);
3178 blk_xor[0] = (1 << 11) | (1 << 13) | (1 << 15) | (1 << 17);
3180 blk[off] = (1 << 10) | (1 << 12);
3204 blk_xor[off] = (1 << 10) | (1 << 11) | (1 << 12);
3208 assert((d64 & 1) && (d64 & (1ull << 60)));
3229 cout <<
"---------------------------- TestBlockCountXORChange() test OK" << endl;
3244 template<
typename T>
3246 const unsigned* src,
3251 T*
end = dest + dest_len;
3252 unsigned bitval = (*src) & 1u;
3257 unsigned bit_idx = 0;
3258 unsigned bitval_next;
3260 unsigned val = *src;
3266 while (
val == 0 ||
val == 0xffffffff)
3268 bitval_next =
val ? 1 : 0;
3269 if (bitval != bitval_next)
3271 *pcurr++ = (
T)(bit_idx-1);
3272 assert((pcurr-1) == (dest+1) || *(pcurr-1) > *(pcurr-2));
3277 bitval = bitval_next;
3279 bit_idx += unsigned(
sizeof(*src) * 8);
3280 if (bit_idx >= bits)
3293 bitval_next =
val &
mask ? 1 : 0;
3294 if (bitval != bitval_next)
3296 *pcurr++ = (
T)(bit_idx-1);
3297 assert((pcurr-1) == (dest+1) || *(pcurr-1) > *(pcurr-2));
3298 bitval = bitval_next;
3306 if (bit_idx >= bits)
3315 *pcurr = (
T)(bit_idx-1);
3316 unsigned len = (unsigned)(pcurr - dest);
3317 *dest = (
T)((*dest & 7) + (
len << 3));
3363 cout <<
"---------------------------- TestBlockToGAP" << endl;
3389 unsigned test_arr[] = { 1, 2, 3, (~0u << 4), ~0u, (~0u >> 1), (~0u >> 2) };
3390 unsigned arr_size =
sizeof(test_arr)/
sizeof(test_arr[0]);
3395 for (
i = 0;
i < arr_size; ++
i)
3397 blk[k] = test_arr[
i];
3419 cout <<
"Test arr - ok" << endl;
3458 cout <<
"mask shift - ok" << endl;
3468 unsigned max_try = 1000000;
3469 for (
unsigned k = 0; k < max_try; ++k)
3475 blk[idx] |= (unsigned)rand();
3477 blk[idx] |= (unsigned)rand();
3479 blk[idx] |= (unsigned)rand();
3481 blk[idx] |= (unsigned)rand();
3486 blk[idx] |= (~0u << (rand()%31));
3506 cout <<
"---------------------------- TestBlockToGAP OK" << endl;
3514 cout <<
"---------------------------- ShiftRotate test" << endl;
3522 blk0[
i] = blk1[
i] = 1;
3530 if (blk0[
i] != 2 || blk0[
i] != blk1[
i])
3532 cerr <<
"Cyclic rotate check failed" << endl;
3542 if (blk0[
i] != 4 || blk0[
i] != blk1[
i])
3544 cerr <<
"Cyclic rotate check failed" << endl;
3551 blk0[
i] = blk1[
i] = 1u << 31;
3558 if (blk0[
i] != 1 || blk0[
i] != blk1[
i])
3560 cerr <<
"Cyclic rotate check failed" << endl;
3567 blk0[
i] = blk1[
i] = unsigned(rand());
3577 if (blk0[
i] != blk1[
i])
3579 cerr <<
"Stress Cyclic rotate check failed" << endl;
3588 unsigned acc0, acc1;
3592 blk0[
i] = blk1[
i] = 1;
3600 if (blk0[
i] != blk1[
i])
3602 cerr <<
"1. SHIFT-r check failed" << endl;
3611 blk0[
i] = blk1[
i] = (1u << 31);
3619 if (blk0[
i] != blk1[
i])
3621 cerr <<
"2. SHIFT-r check failed" << endl;
3628 blk0[
i] = blk1[
i] = unsigned(rand());
3636 assert(
bool(acc0) ==
bool(acc1));
3640 if (blk0[
i] != blk1[
i])
3642 cerr <<
"Stress SHIFT-r check failed" << endl;
3648 cout <<
"---------------------------- ShiftRotate test OK" << endl;
3654 cout <<
"---------------------------- BlockBitInsertTest test" << endl;
3661 blk0[
i] = blk1[
i] = 0;
3674 assert(blk0[0]==(3u << 1));
3680 assert(blk0[0]==(~0u & ~(1u << 1)));
3686 assert(blk0[0]==(~0u >> 1));
3693 assert(blk0[0]==(1u << 31));
3694 assert(blk0[1]==(3u << 1));
3698 cout <<
"bit-insert stress 0..." << endl;
3701 blk0[
i] = blk1[
i] = 0;
3704 for (
i = 0;
i < 65536; ++
i)
3707 assert(co == 0 ||
i == 65535);
3713 for (
unsigned k = 0; k < 65536; ++k)
3724 if (blk0[
i] != blk1[
i])
3726 cerr <<
"Stress insert(0) failed" << endl;
3731 cout <<
"OK" << endl;
3733 cout <<
"bit-insert stress 1..." << endl;
3738 for (
i = 0;
i < 65536; ++
i)
3741 assert(co == 1 ||
i == 65535);
3742 for (
unsigned k = 0; k < 65536; ++k)
3757 if (blk0[
i] != blk1[
i])
3759 cerr <<
"Stress insert(1) failed" << endl;
3764 cout <<
"OK" << endl;
3767 cout <<
"---------------------------- BlockBitInsertTest test OK" << endl;
3774 cout <<
"---------------------------- BlockBitEraseTest test" << endl;
3799 assert(blk0[0] == 1u << 31u);
3839 cout <<
"bit-insert-erase stress 0..." << endl;
3846 for (
unsigned i = 65535;
i != 0; --
i)
3863 unsigned control = 0;
3864 for (
unsigned k = 0; k < 65536; ++k)
3872 cerr <<
t <<
" " << control << endl;
3873 cerr <<
"i=" <<
i <<
" cnt=" <<
cnt;
3874 cerr <<
" CNT==1 failed!" << endl;
3880 std::cout << c << endl;
3887 for (
unsigned i = 65535;
i != 0; --
i, ++j)
3923 for (
unsigned i = 0;
i < 65535; ++
i)
3925 for(
unsigned j =
i; j < 65535; ++j)
3928 unsigned bitcount = j -
i + 1;
3936 for (
unsigned k =
i + bitcount/2; k <
i+bitcount; ++k)
3961 cout <<
"ok" << endl;
3963 cout <<
"---------------------------- BlockBitEraseTest test OK" << endl;
3969 cout <<
"---------------------------- Empty bvector test" << endl;
3975 bvect bv3(bv1 & bv2);
3976 bvect bv4 = (bv1 & bv2);
3978 std::vector< bvect > v;
3979 v.push_back(
bvect());
3987 cerr <<
"Failed count_range()" << endl;
3990 bool b = bv1.
test(0);
3993 cerr <<
"Failed test" << endl;
4000 cerr <<
"Failed any" << endl;
4007 cerr <<
"Failed set_bit" << endl;
4016 cerr <<
"Failed set_bit" << endl;
4025 cerr <<
"Failed set_range" << endl;
4031 cerr <<
"Failed set_range(0,1)" << endl;
4040 cerr <<
"Failed clear_bit" << endl;
4049 cerr <<
"Failed clear()" << endl;
4058 cerr <<
"Failed invert()" << endl;
4066 if (bv1.
any() || bv2.
any())
4068 cerr <<
"Failed swap()" << endl;
4076 cerr <<
"Failed get_first()" << endl;
4084 cerr <<
"Failed extract_next()" << endl;
4092 if (
st.memory_used == 0)
4094 cerr <<
"Failed calc_stat()" << endl;
4105 cerr <<
"Failed bit_or()" << endl;
4112 cerr <<
"Failed bit_or()" << endl;
4118 cerr <<
"Failed bit_or()" << endl;
4129 cerr <<
"Failed bit_and()" << endl;
4136 cerr <<
"Failed bit_and()" << endl;
4142 cerr <<
"Failed bit_and()" << endl;
4153 cerr <<
"Failed calc_stat()" << endl;
4166 cerr <<
"Failed compare()" << endl;
4174 cerr <<
"Failed compare()" << endl;
4181 cerr <<
"Failed compare()" << endl;
4193 cerr <<
"failed first enumerator" << endl;
4207 cout <<
"---------------------------- Empty bvector test OK" << endl;
4217 cout <<
"---------------------------- Basic functinality test" << endl;
4227 printf(
"\nBasic functionality test.\n");
4241 bvect bv { 65536, 65538};
4245 bv.clear_range(65536, 65536+65535);
4255 bv.
init(256,
false);
4269 cout <<
"test data generation... " << endl;
4278 bm::id_t pos1, pos2, pos3, pos4, pos5;
4279 auto rf1 =
FindRank(bvect_full,
i+1, 0, pos1);
4280 auto rf2 = bvect_full.
find_rank(
i+1, 0, pos2);
4281 auto rf3 = bvect_full.
find_rank(
i+1, 0, pos3);
4282 auto rf4 = bvect_full.
select(
i+1, pos4, bc_arr);
4288 if (pos1 != pos2 || pos1 != pos3 || pos1 != pos4)
4291 cerr <<
"1.Rank check error!\n"
4292 <<
" pos1 = " << pos1
4293 <<
" pos2 = " << pos2
4294 <<
" pos3 = " << pos3
4295 <<
" pos4 = " << pos4
4302 bvect bv_opt(bvect_full);
4305 auto rf5 = bv_opt.
select(
i+1, pos5, bc_arr);
4316 cout <<
"Rank check 2" << endl;
4321 auto rf1 =
FindRank(bvect_full1,
i+1, 0, pos1);
4322 auto rf2 = bvect_full1.
find_rank(
i+1, 0, pos2);
4323 auto rf3 = bvect_full1.
find_rank(
i+1, 0, pos3);
4324 auto rf4 = bvect_full1.
select(
i+1, pos4, bc_arr1);
4329 if (pos1 != pos2 || pos1 != pos3 || pos1 != pos4)
4332 cerr <<
"2.Rank check error!\n"
4333 <<
" pos1 = " << pos1
4334 <<
" pos2 = " << pos2
4335 <<
" pos3 = " << pos3
4336 <<
" pos4 = " << pos4
4344 cout <<
"\r" <<
i <<
" / " <<
ITERATIONS << flush;
4361 if (bvect_full1 != bvect_full)
4363 cout <<
"set_range failed!" << endl;
4372 unsigned count_min = 0;
4380 cout <<
"Rank check 3" << endl;
4387 cout <<
"Rank check 4" << endl;
4394 unsigned count_full = bvect_full.
count();
4396 if (count_min == count_full)
4398 printf(
"simple count test ok.\n");
4402 printf(
"simple count test failed count_min = %i count_full = %i\n",
4403 count_min, count_full);
4432 cout <<
"Random step filling" << endl;
4434 for (
i = (
unsigned)rand()%10;
i <
ITERATIONS;
i+=(unsigned)rand()%10)
4448 bv2[200] = bv2[700] = bv2[500] =
true;
4452 if (bv1.
count() != 3)
4454 cout <<
"Swap test failed!" << endl;
4458 if (bv2.
count() != 2)
4460 cout <<
"Swap test failed!" << endl;
4486 std::vector<bm::id_t> &
v2,
4487 std::vector<bm::id_t> &v3,
4488 unsigned vector_max)
4491 for (j = 0; j < vector_max; j += 2)
4493 for (j = 0; j < vector_max; j += 5)
4495 for (j = 0; j < vector_max; j += 120)
4503 cout <<
"---------------------------- Bvector BULK set test" << endl;
4507 unsigned ids[] = { 0 };
4509 bvect bv1, bv2, bv3;
4512 for (
unsigned i = 0;
i <
sizeof(ids)/
sizeof(ids[0]); ++
i)
4518 bv2.
set(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4526 bv2.
keep(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4535 bv2.
set(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4538 cout <<
cnt << endl;
4553 bv2.
set(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4560 cout <<
cnt << endl;
4567 unsigned ids[] = {65536 };
4571 bv1.
set(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4573 bv1.
keep(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4574 cout << bv1.
size() << endl;
4579 unsigned ids[] = {65536, 1280000, 65535 };
4582 for (
unsigned i = 0;
i <
sizeof(ids)/
sizeof(ids[0]); ++
i)
4585 bv2.
set(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4589 bv2.
keep(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4596 unsigned ids[] = { 0, 1, 2, 3, 4, 5, 256, 1024, 1028, 256000 };
4599 for (
unsigned i = 0;
i <
sizeof(ids)/
sizeof(ids[0]); ++
i)
4601 bv2.
set(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4611 unsigned keep_cnt =
sizeof(ids)/
sizeof(ids[0]);
4613 unsigned cnt_inv2 = bv_inv.
count();
4614 assert(cnt_inv2 == keep_cnt);
4615 for (
unsigned i = 0;
i <
sizeof(ids)/
sizeof(ids[0]); ++
i)
4621 bvect bv3, bv4, bv5;
4628 for (
unsigned i = 0;
i <
sizeof(ids)/
sizeof(ids[0]); ++
i)
4634 bv4.
set(&ids[0],
sizeof(ids)/
sizeof(ids[0]));
4645 unsigned vector_max = 4000000;
4646 std::vector<bm::id_t> v1,
v2, v3;
4649 for (
unsigned k = 0; k < 2; ++ k)
4652 bvect bv1, bv2, bv3, bv11;
4653 bvect bv1c, bv2c, bv3c;
4657 for (
unsigned i = 0;
i < v1.size(); ++
i)
4665 for (
unsigned i = 0;
i <
v2.size(); ++
i)
4667 for (
unsigned i = 0;
i < v3.size(); ++
i)
4675 bv1.
set(&v1[0],
unsigned(v1.size()));
4676 bv2.
set(&
v2[0],
unsigned(
v2.size()));
4677 bv3.
set(&v3[0],
unsigned(v3.size()));
4680 bvu.
set(&v1[0],
unsigned(v1.size()));
4681 bvu.
set(&
v2[0],
unsigned(
v2.size()));
4682 bvu.
set(&v3[0],
unsigned(v3.size()));
4684 cout << bv1.
count() <<
" " << bv1c.
count() << endl;
4704 std::random_device rd;
4705 std::mt19937
g(rd());
4707 std::shuffle(v1.begin(), v1.end(),
g);
4708 std::shuffle(
v2.begin(),
v2.end(),
g);
4709 std::shuffle(v3.begin(), v3.end(),
g);
4716 cout <<
"Bulk bvector<>::set() stress.." << endl;
4718 unsigned vector_max =40000000;
4719 unsigned delta_max = 65537;
4723 std::vector<bm::id_t> v1;
4729 for (
unsigned i = 0;
i < vector_max;
i+=
delta)
4736 bv1.
set(&v1[0],
unsigned(v1.size()));
4742 cerr <<
"1.Failed bulk set test at delta=" <<
delta << endl;
4748 cerr <<
"2.Failed bulk set test at delta=" <<
delta << endl;
4756 bv3.
keep(&v1[0],
unsigned(v1.size()));
4757 bv4.
set(&v1[0],
unsigned(v1.size()));
4761 cerr <<
"3.Failed keep() test at delta=" <<
delta << endl;
4766 bv3.
keep(&v1[0], 1);
4776 if (
delta % 256 == 0)
4779 cout <<
"\r" <<
delta <<
"/" << delta_max << flush;
4787 cout <<
"---------------------------- Bvector BULK set test OK\n" << endl;
4795 cout <<
"---------------------------- Find Rank test" << endl;
4808 rf3 = bv1.
find_rank(1, 20, pos1, bc_arr1);
4815 rf3 = bv1.
find_rank(2, 30, pos1, bc_arr1);
4823 cout <<
"Test bvector<>::select()" << endl;
4840 for (
i = 0;
i <=
r; ++
i)
4844 bool f = bv.
select(ri, pos, rs_idx);
4848 bool f = bv.
select(
i+1, pos, rs_idx);
4852 cout <<
"Find Rank test stress 1\n" << endl;
4855 const unsigned max_size = 2000000;
4857 for (
unsigned i = 0;
i < max_size;)
4860 i += (unsigned)rand()%5;
4866 for (
unsigned i = 0;
i < max_size; ++
i)
4878 cerr <<
"Rank cmp test failed! i=" <<
i
4887 rf3 = bv1.
find_rank(
i, max_size-
i, pos1, bc_arr1);
4893 cerr <<
"Rank cmp test failed! i=" <<
i
4902 cout <<
"\r" <<
i <<
"/" << max_size << flush;
4907 cout <<
"---------------------------- Find Rank test OK" << endl;
4913 cout <<
"---------------------------- Bvector inc test" << endl;
4938 cout << bv1.
count() << endl;
4967 cout <<
"---------------------------- Bvector inc test OK" << endl;
4990 cout <<
"---------------------------- Bvector Optimize test" << endl;
5142 cout <<
"---------------------------- Bvector Optimize test OK" << endl;
5151 unsigned max = 40000000,
5152 unsigned fill_factor = 65536)
5155 unsigned ff = fill_factor / 10;
5161 if (ff > fill_factor)
5162 ff = fill_factor / 10;
5170 unsigned count = 30,
5171 unsigned vector_max = 40000000,
5178 unsigned cnt1 = (
count / 2);
5182 for (
i = 0;
i < cnt1; ++
i)
5184 std::unique_ptr<bvect> bv (
new bvect);
5189 target->push_back(std::move(*bv));
5192 unsigned fill_factor = 10;
5195 std::unique_ptr<bvect> bv (
new bvect);
5200 target->push_back(std::move(*bv));
5209 cout <<
"---------------------------- Bvector SHIFT test" << endl;
5234 auto cnt1 = bv.
count();
5236 auto cnt2 = bv.
count();
5238 bool b = bv.
test(0);
5246 auto cnt1 = bv.
count();
5248 auto cnt2 = bv.
count();
5264 auto cnt1 = bv.
count();
5266 auto cnt2 = bv.
count();
5310 for (
unsigned i = 0;
i < 65536; ++
i)
5323 auto bcnt =
st.bit_blocks +
st.gap_blocks;
5326 for (
unsigned i = 0+1;
i < 65536+1; ++
i)
5334 cout <<
" inverted test" << endl;
5340 unsigned cnt1 = bv.
count();
5347 auto bcnt =
st.bit_blocks +
st.gap_blocks;
5353 cout <<
" 3-bit optimized test" << endl;
5370 cout <<
" carry-over test" << endl;
5374 unsigned idx = bv.get_first();
5376 carry_over = bv.shift_left();
5378 idx = bv.get_first();
5379 std::cout << idx << endl;
5385 cout <<
" 4278190080 test" << endl;
5387 bvect bv { 4278190080 };
5389 unsigned idx = bv.get_first();
5390 assert(idx == 4278190080-1);
5392 idx = bv.get_first();
5393 assert(idx == 4278190080-2);
5397 cout <<
" 4278190080 (optimized) test" << endl;
5398 bvect bv { 4278190080 };
5401 unsigned idx = bv.get_first();
5402 assert(idx == 4278190080-1);
5404 idx = bv.get_first();
5405 assert(idx == 4278190080-2);
5409 std::cout <<
"\nShift-L stress (1 bit shift)..\n" << endl;;
5416 auto bcnt =
st.bit_blocks +
st.gap_blocks;
5419 std::chrono::time_point<std::chrono::steady_clock> s;
5420 std::chrono::time_point<std::chrono::steady_clock>
f;
5422 s = std::chrono::steady_clock::now();
5424 for( ; start; --start)
5429 cout <<
"CO at " << start << endl;
5444 if ((start % (1024 * 1024)) == 0)
5446 f = std::chrono::steady_clock::now();
5448 auto d = std::chrono::duration <double, std::milli> (diff).count();
5449 cout <<
"\r" << start <<
" (" << d <<
") " << flush;
5457 bcnt =
st.bit_blocks +
st.gap_blocks;
5460 s = std::chrono::steady_clock::now();
5467 std::cout <<
"\nShift-R stress (1 bit shift)..\n" << endl;
5475 auto bcnt =
st.bit_blocks +
st.gap_blocks;
5478 std::chrono::time_point<std::chrono::steady_clock> s;
5479 std::chrono::time_point<std::chrono::steady_clock>
f;
5481 s = std::chrono::steady_clock::now();
5488 cout <<
"CO at " << start << endl;
5496 bcnt =
st.bit_blocks +
st.gap_blocks;
5502 cout <<
"CO at " << start << endl;
5511 bcnt =
st.bit_blocks +
st.gap_blocks;
5517 if ((start % (1024 * 1024)) == 0)
5524 f = std::chrono::steady_clock::now();
5526 auto d = std::chrono::duration <double, std::milli> (diff).count();
5528 cout <<
"\r" << start <<
" (" << d <<
") " << flush;
5534 bcnt =
st.bit_blocks +
st.gap_blocks;
5537 s = std::chrono::steady_clock::now();
5545 std::cout <<
"\nShift-R stress (large vector shift)..\n" << endl;
5548 bvect bv_control(bv);
5550 unsigned max_shifts = 10000;
5551 for (
unsigned i = 0;
i < max_shifts; ++
i)
5560 cout <<
"\r" <<
i <<
"/" << max_shifts << flush;
5569 cout <<
"\nAggregator based SHIT-R tests..." << endl;
5571 const unsigned int REPEATS = 300;
5577 std::vector<bvect> bv_coll1;
5583 for (
unsigned k = 0; k < bv_coll1.size(); ++k)
5585 agg.
add(&bv_coll1[k]);
5588 for (
unsigned i = 0;
i < REPEATS; ++
i)
5591 for (
unsigned k = 0; k < bv_coll1.size(); ++k)
5603 cerr <<
"Shift-R compare failure!" << endl;
5611 auto cnt_c = bv1.
count();
5619 cout <<
"\n---------------------------- Bvector SHIFT test OK" << endl;
5625 cout <<
"\n---------------------------- Bvector INSERT test" << endl;
5628 bvect bv { 1, 2, 3 };
5629 bvect bv_c { 2, 3, 4 };
5634 int cmp = bv.compare(bv_c);
5652 bvect bv { 1, 2, 3 };
5653 bvect bv_c { 0, 2, 3, 4 };
5658 int cmp = bv.compare(bv_c);
5696 bvect bv { 1, 20, 65535 };
5697 bvect bv_c { 1, 20, 65535, 65536 };
5702 int cmp = bv.compare(bv_c);
5725 bv.
insert(120303030,
true);
5732 bvect bv { 120303030u, 120303031u };
5735 bv1.
insert(120303031u,
true);
5741 bv1.
insert(120303031u,
true);
5749 bv.
set_range(1203030u, 1203030u+65535u*10u);
5752 bv1.
insert(1203030u+10,
false);
5758 std::cout <<
"INSERT GAP (random)..\n";
5765 for (
unsigned i = 0;
i < 1000; ++
i)
5767 unsigned idx = (unsigned)rand() % 65535;
5768 unsigned val = (unsigned)rand() & 1;
5769 bv.insert(idx,
val);
5779 bv.insert(idx,
val);
5792 std::cout <<
"INSERT stress (large vector insert)..\n";
5795 bvect bv_control(bv);
5797 unsigned max_shifts = 10000;
5798 for (
unsigned i = 0;
i < max_shifts; ++
i)
5804 unsigned i_pos = (unsigned)rand()%40000000;