private void rehash(int newLength) { // System.out.println( "REHASH: " + array.length + " " + newLength + " " + currentSize ); AnyType[] oldArray = array; // Create a new double-sized, empty table allocateArray(nextPrime(newLength)); currentSize = 0; // Copy table over for (AnyType str : oldArray) if (str != null) insert(str); }
// Simple main public static void main(String[] args) { long cumulative = 0; final int NUMS = 2000000; final int GAP = 37; final int ATTEMPTS = 10; System.out.println("Checking... (no more output means success)"); for (int att = 0; att < ATTEMPTS; att++) { System.out.println("ATTEMPT: " + att); CuckooHashTable<String> H = new CuckooHashTable<String>(new StringHashFamily(3)); // QuadraticProbingHashTable<String> H = new QuadraticProbingHashTable<>( ); long startTime = System.currentTimeMillis(); for (int i = GAP; i != 0; i = (i + GAP) % NUMS) H.insert("" + i); for (int i = GAP; i != 0; i = (i + GAP) % NUMS) if (H.insert("" + i)) System.out.println("OOPS!!! " + i); for (int i = 1; i < NUMS; i += 2) H.remove("" + i); for (int i = 2; i < NUMS; i += 2) if (!H.contains("" + i)) System.out.println("Find fails " + i); for (int i = 1; i < NUMS; i += 2) { if (H.contains("" + i)) System.out.println("OOPS!!! " + i); } long endTime = System.currentTimeMillis(); cumulative += endTime - startTime; if (H.capacity() > NUMS * 4) System.out.println("LARGE CAPACITY " + H.capacity()); } System.out.println("Total elapsed time is: " + cumulative); }