static void apply( const MyTable& table, int i ) { MyTable::const_accessor a; const MyTable::const_accessor& ca = a; bool b = table.find( a, MyKey::make(i) ); ASSERT( b==(table.count(MyKey::make(i))>0), NULL ); ASSERT( b==!a.empty(), NULL ); ASSERT( b==UseKey(i), NULL ); if( b ) { AssertSameType( &*ca, static_cast<const MyTable::value_type*>(0) ); ASSERT( ca->second.value_of()==~(i*i), NULL ); ASSERT( (*ca).second.value_of()==~(i*i), NULL ); } }
static void apply( MyTable& table, int i ) { bool b; if(i&4) { if(i&8) { MyTable::const_accessor a; b = table.find( a, MyKey::make(i) ) && table.erase( a ); } else { MyTable::accessor a; b = table.find( a, MyKey::make(i) ) && table.erase( a ); } } else b = table.erase( MyKey::make(i) ); if( b ) ++EraseCount; ASSERT( table.count(MyKey::make(i)) == 0, NULL ); }
void TestRehash() { REMARK("testing rehashing\n"); MyTable w; w.insert( std::make_pair(MyKey::make(-5), MyData()) ); w.rehash(); // without this, assertion will fail MyTable::iterator it = w.begin(); int i = 0; // check for non-rehashed buckets for( ; it != w.end(); i++ ) w.count( (it++)->first ); ASSERT( i == 1, NULL ); for( i=0; i<1000; i=(i<29 ? i+1 : i*2) ) { for( int j=max(256+i, i*2); j<10000; j*=3 ) { MyTable v; FillTable( v, i ); ASSERT(int(v.size()) == i, NULL); ASSERT(int(v.bucket_count()) <= j, NULL); v.rehash( j ); ASSERT(int(v.bucket_count()) >= j, NULL); CheckTable( v, i ); } } }