last Rehash()

From: Tioukov Valeri (valeri@d500na4.na.infn.it)
Date: Thu Apr 29 1999 - 12:54:20 MEST


Hi rooters,

I found that the last Rehash() of the hashtable othen is really last: the
table becomes broken.

As the shortest example Test_THashTable from tcollex.cxx with 4 edited
lines (marked VT:) :

.................................................................................
void Test_THashTable()
{
   Printf(
   "////////////////////////////////////////////////////////////////\n"
   "// Test of THashTable                                         //\n"
   "////////////////////////////////////////////////////////////////"
   );

   int i;

   // Create a hash table with an initial size of 20 (actually the nextprime
   // above 20). No automatic rehashing.
   THashTable ht(20);

   Printf("Filling THashTable");
   Printf("Number of slots before filling: %d", ht.Capacity());
   for (i = 0; i < 100; i++)                   // VT: change loop to 100
      ht.Add(new TObjNum(i));                  // VT: TObjNum instead TObject

   ht.Print();        // VT: printed ok

   Printf("Average collisions: %f", ht.AverageCollisions());

   // rehash the hash table to reduce the collission rate
   ht.Rehash(ht.GetSize());

   ht.Print();         // VT: print 1 empty line

   Printf("Number of slots after rehash: %d", ht.Capacity());
   Printf("Average collisions after rehash: %f", ht.AverageCollisions());
................................................................................


In fact after the last rehash nothing works also in my programs.
Moreother if I declare table with the automatic rehash 
THashTable ht(100,10); for example - the effect depends dramatically on
the parameters

The next code I add to tcollex.cxx as one more example: 

void Test_T()
{
   TObjNum  *x=0, *y=0;

   THashTable *h = new THashTable(100,10);

   for(int i=0; i<2000; i++) {
     x = new TObjNum(i);
     h->Add(x);
   }
   
   y = new TObjNum(10);
   ((TObjNum*)h->FindObject(y))->Print("");      // 1

   printf("%f \n", h->AverageCollisions());
   h->Rehash(h->GetSize());
   printf("%f \n", h->AverageCollisions());

   h->Print();                                  // 2
   ((TObjNum*)h->FindObject(y))->Print("");     // 3
}

This code brakes at line // 1 . If one change the table declaration to
THashTable(100,20); or reduce the cycle to 200 - it works up to line //2.
Line //3 brakes anyway. 

Is it a bug or I do something wrong?
I tested it only on one system RH5.2+egcs-1.0.3

Best regards
Valeri



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:32 MET