static void FillTable( MyTable& x, int n ) {
    for( int i=1; i<=n; ++i ) {
        MyKey key( MyKey::make(-i) ); // hash values must not be specified in direct order
        typename MyTable::accessor a;
        bool b = x.insert(a,key);
        ASSERT(b, NULL);
        a->second.set_value( i*i );
    }
}
 static void apply( MyTable& table, int i ) {
     if( UseKey(i) ) {
         if( i&4 ) {
             MyTable::accessor a;
             table.insert( a, MyKey::make(i) );
             if( i&1 )
                 (*a).second.set_value(i*i);
             else
                 a->second.set_value(i*i);
         } else
             if( i&1 ) {
                 MyTable::accessor a;
                 table.insert( a, std::make_pair(MyKey::make(i), MyData(i*i)) );
                 ASSERT( (*a).second.value_of()==i*i, NULL );
             } else {
                 MyTable::const_accessor ca;
                 table.insert( ca, std::make_pair(MyKey::make(i), MyData(i*i)) );
                 ASSERT( ca->second.value_of()==i*i, 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 );
        }
    }
}