📄 stress.cpp
字号:
//bvect_full->clear_bit(j);/* if (g_cnt_check) { bool b = bvect_full->count_check(); if(!b) { cout << "Count check failed (clear)!" << endl; cout << "bit=" << j << endl; exit(1); } }*/ } } // j//cout << "Checking range filling " << from << "-" << to << endl;//CheckVectors(*bvect_min, *bvect_full, 100000000); i = end; len = rand() % (factor* 10 * bm::gap_max_bits); if (len % 2) { len *= rand() % (factor * 10); } i+=len; if ( (len % 6) == 0) {/*if (set_flag == false){ cout << "Additional Cleaning: " << i << "-" << end << endl;}*/ for(unsigned k=0; k < 1000 && i < max; k+=3,i+=3) { if (set_flag) { bvect_min->set_bit(i); bvect_full->set_bit(i); } else { bvect_min->clear_bit(j); bvect_full->clear_bit(j); } } } } // for i}void FillSetClearIntervals(bvect_mini* bvect_min, bvect* bvect_full, unsigned min, unsigned max, unsigned fill_factor){ FillSetsIntervals(bvect_min, bvect_full, min, max, fill_factor, true); FillSetsIntervals(bvect_min, bvect_full, min, max, fill_factor, false);}void FillSetsRandom(bvect_mini* bvect_min, bvect* bvect_full, unsigned min, unsigned max, unsigned fill_factor){ unsigned diap = max - min; unsigned count; switch (fill_factor) { case 0: count = diap / 1000; break; case 1: count = diap / 100; break; default: count = diap / 10; break; } for (unsigned i = 0; i < count; ++i) { unsigned bn = rand() % count; bn += min; if (bn > max) { bn = max; } bvect_min->set_bit(bn); bvect_full->set_bit(bn); if ( (i % PROGRESS_PRINT) == 0) { cout << "+" << flush; } } cout << "Ok" << endl;}//// Quasi random filling with choosing randomizing method.////void FillSetsRandomMethod(bvect_mini* bvect_min, bvect* bvect_full, unsigned min, unsigned max, int optimize = 0, int method = -1){ if (method == -1) { method = rand() % 5; } unsigned factor;//method = 4; switch (method) { case 0: cout << "Random filling: method - FillSets - factor(0)" << endl; FillSets(bvect_min, bvect_full, min, max, 0); break; case 1: cout << "Random filling: method - FillSets - factor(random)" << endl; factor = rand()%3; FillSets(bvect_min, bvect_full, min, max, factor?factor:1); break; case 2: cout << "Random filling: method - Set-Clear Intervals - factor(random)" << endl; factor = rand()%10; FillSetClearIntervals(bvect_min, bvect_full, min, max, factor); break; case 3: cout << "Random filling: method - FillRandom - factor(random)" << endl; factor = rand()%3; FillSetsRandom(bvect_min, bvect_full, min, max, factor?factor:1); break; default: cout << "Random filling: method - Set Intervals - factor(random)" << endl; factor = rand()%10; FillSetsIntervals(bvect_min, bvect_full, min, max, factor); break; } // switch if (optimize && (method <= 1)) { cout << "Vector optimization..." << flush; bvect_full->optimize(); cout << "OK" << endl; }}void print_mv(const bvect_mini &bvect_min, unsigned size){ unsigned i; for (i = 0; i < size; ++i) { bool bflag = bvect_min.is_bit_true(i) != 0; if (bflag) printf("1"); else printf("0"); if ((i % 31) == 0 && (i != 0)) printf("."); } printf("\n");}void print_gap(const gap_vector& gap_vect, unsigned size){ const gap_word_t *buf = gap_vect.get_buf(); unsigned len = gap_length(buf); printf("[%i:]", *buf++ & 1); for (unsigned i = 1; i < len; ++i) { printf("%i,", *buf++); } printf("\n");}void CheckGAPMin(const gap_vector& gapv, const bvect_mini& bvect_min, unsigned len){ for (unsigned i = 0; i < len; ++i) { int bit1 = (gapv.is_bit_true(i) == 1); int bit2 = (bvect_min.is_bit_true(i) != 0); if(bit1 != bit2) { cout << "Bit comparison failed. " << "Bit N=" << i << endl; assert(0); exit(1); } }}void CheckIntervals(const bvect& bv, unsigned max_bit){ unsigned cnt0 = count_intervals(bv); unsigned cnt1 = 1; bool bit_prev = bv.test(0); for (unsigned i = 1; i < max_bit; ++i) { bool bit = bv.test(i); cnt1 += bit_prev ^ bit; bit_prev = bit; } if (cnt0 != cnt1) { cout << "CheckIntervals error. " << "bm count=" << cnt0 << " Control = " << cnt1 << endl; exit(1); }}template<class T> void CheckCountRange(const T& vect, unsigned left, unsigned right, unsigned* block_count_arr=0){ unsigned cnt1 = vect.count_range(left, right, block_count_arr); unsigned cnt2 = 0;//cout << endl; for (unsigned i = left; i <= right; ++i) { if (vect.test(i)) {// cout << i << " " << flush; ++cnt2; } }//cout << endl; if (cnt1 != cnt2) { cout << "Bitcount range failed!" << "left=" << left << " right=" << right << endl << "count_range()=" << cnt1 << " check=" << cnt2; exit(1); }}unsigned BitCountChange(unsigned word){ unsigned count = 1; unsigned bit_prev = word & 1; word >>= 1; for (unsigned i = 1; i < 32; ++i) { unsigned bit = word & 1; count += bit ^ bit_prev; bit_prev = bit; word >>= 1; } return count;}void DetailedCheckVectors(const bvect_mini &bvect_min, const bvect &bvect_full, unsigned size){ cout << "Detailed check" << endl; //bvect_full.stat(); // detailed bit by bit comparison. Paranoia check. unsigned i; for (i = 0; i < size; ++i) { bool bv_m_flag = bvect_min.is_bit_true(i) != 0; bool bv_f_flag = bvect_full.get_bit(i) != 0; if (bv_m_flag != bv_f_flag) { printf("Bit %u is non conformant. vect_min=%i vect_full=%i\n", i, (int)bv_m_flag, (int)bv_f_flag); cout << "Non-conformant block number is: " << unsigned(i >> bm::set_block_shift) << endl;// throw 110; exit(1); } if (PROGRESS_PRINT) { if ( (i % PROGRESS_PRINT) == 0) { printf("."); } } } printf("\n detailed check ok.\n");}// vectors comparison checkvoid CheckVectors(bvect_mini &bvect_min, bvect &bvect_full, unsigned size, bool detailed){ cout << "\nVectors checking...bits to compare = " << size << endl; cout << "Bitcount summary : " << endl; unsigned min_count = bvect_min.bit_count(); cout << "minvector count = " << min_count << endl; unsigned count = bvect_full.count(); unsigned full_count = bvect_full.recalc_count(); cout << "fullvector re-count = " << full_count << endl; if (min_count != full_count) { cout << "fullvector count = " << count << endl; cout << "Count comparison failed !!!!" << endl; bvect_full.stat(); DetailedCheckVectors(bvect_min, bvect_full, size); exit(1); } if (full_count) { bool any = bvect_full.any(); if (!any) { cout << "Anycheck failed!" << endl; exit(1); } } // get_next comparison cout << "Positive bits comparison..." << flush; unsigned nb_min = bvect_min.get_first(); unsigned nb_ful = bvect_full.get_first(); bvect::counted_enumerator en = bvect_full.first(); unsigned nb_en = *en; if (nb_min != nb_ful) { cout << "!!!! First bit comparison failed. Full id = " << nb_ful << " Min id = " << nb_min << endl; bool bit_f = bvect_full.get_bit(nb_ful); cout << "Full vector'd bit #" << nb_ful << "is:" << bit_f << endl; bool bit_m = (bvect_min.is_bit_true(nb_min) == 1); cout << "Min vector'd bit #" << nb_min << "is:" << bit_m << endl; bvect_full.stat(); DetailedCheckVectors(bvect_min, bvect_full, size); exit(1); } if (full_count) { unsigned bit_count = 1; unsigned en_prev = nb_en; do { nb_min = bvect_min.get_next(nb_min); if (nb_min == 0) { break; } en_prev = nb_en; ++en; nb_en = *en;// nb_en = bvect_full.get_next(nb_en); ++bit_count; if (nb_en != nb_min) { nb_ful = bvect_full.get_next(en_prev); cout << "!!!!! next bit comparison failed. Full id = " << nb_ful << " Min id = " << nb_min << " Enumerator = " << nb_en << endl; // bvect_full.stat(); // DetailedCheckVectors(bvect_min, bvect_full, size); exit(1); } if ( (bit_count % PROGRESS_PRINT) == 0) { cout << "." << flush; } } while (en.valid()); if (bit_count != min_count) { cout << " Bit count failed." << " min = " << min_count << " bit = " << bit_count << endl; exit(1); } } cout << "OK" << endl; return; }void ClearAllTest(){ bvect bvect_full; for (int i = 0; i < 100000; ++i) { bvect_full.set_bit(i); } bvect_full.optimize(); bvect_full.clear(); bvect_full.stat(); int count = bvect_full.count(); assert(count == 0); bvect_full.stat();}void WordCmpTest(){ cout << "---------------------------- WordCmp test" << endl; for (int i = 0; i < 10000000; ++i) { unsigned w1 = rand(); unsigned w2 = rand(); int res = wordcmp0(w1, w2); int res2 = wordcmp(w1, w2); if (res != res2) { printf("WordCmp failed !\n"); exit(1); } res = wordcmp0((unsigned)0U, (unsigned)w2); res2 = wordcmp((unsigned)0U, (unsigned)w2); if (res != res2) { printf("WordCmp 0 test failed !\n"); exit(1); } res = wordcmp0((unsigned)~0U, (unsigned)w2); res2 = wordcmp((unsigned)~0U, (unsigned)w2); if (res != res2) { printf("WordCmp ~0 test failed !\n"); exit(1); } res = wordcmp0((unsigned)w2, (unsigned)0); res2 = wordcmp((unsigned)w2, (unsigned)0); if (res != res2) { printf("WordCmp 0-2 test failed !\n"); exit(1); } } cout << "Ok." << endl;}void BasicFunctionalityTest(){ cout << "---------------------------- Basic functinality test" << endl; assert(ITERATIONS < BITVECT_SIZE); bvect_mini bvect_min(BITVECT_SIZE); bvect bvect_full; bvect bvect_full1; printf("\nBasic functionality test.\n"); // filling vectors with regular values unsigned i; for (i = 0; i < ITERATIONS; ++i) { bvect_min.set_bit(i); bvect_full.set_bit(i); } bvect_full1.set_range(0, ITERATIONS-1); CheckCountRange(bvect_full, 0, ITERATIONS); CheckCountRange(bvect_full, 10, ITERATIONS+10); if (bvect_full1 != bvect_full) { cout << "set_range failed!" << endl; bvect_full1.stat(); exit(1); } bvect_full.stat(); bvect_full1.stat(); // checking the results
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -