Пример #1
0
 public int Search(Info Key)
 {
     int Index, Offset = 0;
     do
     {
         Index = DoubleHash(Key, Offset);
         if (Table[Index] == null)
             return -1;
         if (Table[Index].Data == Key.Data)
             return Index;
         else
             ++Offset;
     } while (Table[Index] != null && Offset != Size);
     return -1;
 }
Пример #2
0
 public void Insert(Info Key)
 {
     int Index, Offset = 0;
     do
     {
         Index = DoubleHash(Key, Offset);
         if (Table[Index] == null)
         {
             Table[Index] = Key;
             return;
         }
         else
             ++Offset;
     } while (Offset != Size);
     Error err = new Error("Переполнение хеш-таблицы!");
     throw err;
 }
Пример #3
0
 private int HashFunction1(Info Key)
 {
     int a = 3, b = 7;
     int p = 211;
     return ((a * Key.Data + b) % p) % Size;
 }
Пример #4
0
 private int HashFunction2(Info Key)
 {
     int a = 5, b = 11;
     int p = 199;
     return 1 + ((a * Key.Data + b) % p) % (Size - 1);
 }
Пример #5
0
 private int DoubleHash(Info Key, int Offset)
 {
     return (HashFunction1(Key) + Offset * HashFunction2(Key)) % Size;
 }