int out_bset_test(bset& bst, int* ins, unsigned int& in_cts, int* outs, unsigned int& out_cts, pm_random& rand_gen) { if ( out_cts == 0 ) return 0; int k = rand_gen.rand() % out_cts; int_swap(outs[k], outs[out_cts-1]); if ( bst.member((void*)outs[out_cts-1]) != 0 ) { cerr << "can still find " << outs[out_cts-1] << "\n"; return -1; } //cerr << "--------------> inserting " << outs[out_cts-1] << "\n"; bst.insert((void*)outs[out_cts-1]); if ( bst.member((void*)outs[out_cts-1]) == 0 ) { cerr << "can't find " << outs[out_cts-1] << "\n"; return -1; } ins[in_cts++] = outs[out_cts-1]; out_cts--; return 0; }
int bset_test(unsigned int in_cts, unsigned int out_cts, pm_random& rand_gen, unsigned int cycles) { int ok = 0; int* ins = new int[in_cts+out_cts]; int* outs = new int[in_cts+out_cts]; bset bst(void_eq, void_ls); for ( int i=0; i<in_cts; i++ ) { ins[i] = i + 1; bst.insert((void*)ins[i]); } for ( i=0; i<out_cts; i++ ) { outs[i] = i + in_cts + 1; } for ( i=0; i<cycles; i++ ) { if ( rand_gen.rand_01() > 0.5 ) ok |= in_bset_test(bst, ins, in_cts, outs, out_cts, rand_gen); else ok |= out_bset_test(bst, ins, in_cts, outs, out_cts, rand_gen); } delete ins; delete outs; return ok; }
int in_bset_test(bset& bst, int* ins, unsigned int& in_cts, int* outs, unsigned int& out_cts, pm_random& rand_gen) { if ( in_cts == 0 ) return 0; int k = rand_gen.rand() % in_cts; int_swap(ins[k], ins[in_cts-1]); //cerr << "<-------------- removing " << ins[in_cts-1] << "\n"; long j = (long)bst.remove((void*)ins[in_cts-1]); if ( j != ins[in_cts-1] ) { cerr << "can't correctly remove " << ins[in_cts-1] << "\n"; return -1; } if ( bst.member((void*)ins[in_cts-1]) != 0 ) { cerr << "element " << ins[in_cts-1] << " still in the set\n"; return -1; } outs[out_cts++] = ins[in_cts-1]; in_cts--; return 0; }
void atoi_fast::init(int r, int, pm_random& rdm_generator) { v_entries = 256; v_range = r; v_mask = 0; v_tbl = new char[v_entries]; for ( int i = 0; i < v_entries; i++ ) v_tbl[i] = i; for ( i = 0; i < v_entries - 1; i++ ) { char_swap(v_tbl[rdm_generator.rand() % ( v_entries - i ) + i], v_tbl[i] ); } v_no_bytes = 4; }