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; }
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; }
private int HashFunction1(Info Key) { int a = 3, b = 7; int p = 211; return ((a * Key.Data + b) % p) % Size; }
private int HashFunction2(Info Key) { int a = 5, b = 11; int p = 199; return 1 + ((a * Key.Data + b) % p) % (Size - 1); }
private int DoubleHash(Info Key, int Offset) { return (HashFunction1(Key) + Offset * HashFunction2(Key)) % Size; }