/** * Searches for an entry with key equal to x (which is known to have primary * hash value hash1), returning the index at which it was found, or returning * -(a+1) where a is the index of the first empty or available slot that can * be used to store a new such entry. Uses secondary hashing function * h'(k) = 7 - k mod 7, where the secondary prime factor 7 is the smallest * prime less than the current capacity. * * @param hash1 the precalculated hash value of the given key * @param x the key * @return index of found entry or if not found */ protected int getLocation(int hash1, K x) { int i = hash1; int hash2 = 7 - x.hashCode() % 7; int present = -1; do { if (isAvailable(i)) { if (present == -1) { present = i; } if (table[i] == null) { break; } } else if (table[i].getKey().equals(x)) { return i; } i = (i + hash2) % capacity; } while (i != hash1); return -(present + hash2); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)