https://en.wikipedia.org/wiki/Cuckoo_hashing
Cuckoo hashing is a scheme for resolving hash collisions of values of hash functions in a table, with worst-case constant lookup time. The name derives from the behavior of some species of cuckoo, where the cuckoo chick pushes the other eggs or young out of the nest when it hatches; analogously, inserting a new key into a cuckoo hashing table may push an older key to a different location in the table.
When a new key is inserted, a greedy algorithm is used: The new key is inserted in one of its two possible locations, "kicking out", that is, displacing, any key that might already reside in this location. This displaced key is then inserted in its alternative location, again kicking out any key that might reside there, until a vacant position is found, or the procedure would enter aninfinite loop. In the latter case, the hash table is rebuilt in-place using new hash functions:
Lookup requires inspection of just two locations in the hash table, which takes constant time in the worst case (see Big O notation). This is in contrast to many other hash table algorithms, which may not have a constant worst-case bound on the time to do a lookup.
https://highlyscalable.wordpress.com/2011/12/29/ultimate-sets-and-maps-for-java-p1/
In CuckooSet we can’t guarantee that insertion will find a place for new element, even after multiple permutations of the existing elements (maximum number of permutations is regulated by insertRounds). So, increase of the table size and rehashing is an integral part of the implementation.
he Cuckoo Hashing offers a trade off between the memory consumption and performance/stability of the lookups. It typically uses two tables instead of one, but both successful and unsuccessful lookups are performed without iterative jumps (compare contains methods in OpenAddressingSet and CuckooSet)..
https://leijiangcoding.wordpress.com/2015/04/24/hash-tables-with-worst-case-o1-access-cuckoo-hashing/
http://coolshell.cn/articles/17225.html#more-17225
Cuckoo Filter的论文和PPT:Cuckoo Filter: Practically Better Than Bloom
http://users.cis.fiu.edu/~weiss/dsaajava3/code/CuckooHashTable.java
Cuckoo hashing is a scheme for resolving hash collisions of values of hash functions in a table, with worst-case constant lookup time. The name derives from the behavior of some species of cuckoo, where the cuckoo chick pushes the other eggs or young out of the nest when it hatches; analogously, inserting a new key into a cuckoo hashing table may push an older key to a different location in the table.
When a new key is inserted, a greedy algorithm is used: The new key is inserted in one of its two possible locations, "kicking out", that is, displacing, any key that might already reside in this location. This displaced key is then inserted in its alternative location, again kicking out any key that might reside there, until a vacant position is found, or the procedure would enter aninfinite loop. In the latter case, the hash table is rebuilt in-place using new hash functions:
Lookup requires inspection of just two locations in the hash table, which takes constant time in the worst case (see Big O notation). This is in contrast to many other hash table algorithms, which may not have a constant worst-case bound on the time to do a lookup.
https://highlyscalable.wordpress.com/2011/12/29/ultimate-sets-and-maps-for-java-p1/
In CuckooSet we can’t guarantee that insertion will find a place for new element, even after multiple permutations of the existing elements (maximum number of permutations is regulated by insertRounds). So, increase of the table size and rehashing is an integral part of the implementation.
he Cuckoo Hashing offers a trade off between the memory consumption and performance/stability of the lookups. It typically uses two tables instead of one, but both successful and unsuccessful lookups are performed without iterative jumps (compare contains methods in OpenAddressingSet and CuckooSet)..
https://leijiangcoding.wordpress.com/2015/04/24/hash-tables-with-worst-case-o1-access-cuckoo-hashing/
public class CuckooSet { private int[] keysT1; private int[] keysT2; private int tableLength; private int hashShift; private int rehashCounter = 0; private double loadFactor; private int capacity; private int insertRounds; private static final long H1 = 2654435761L; private static final long H2 = 0x6b43a9b5L; private static final long INT_MASK = 0x07FFFFFFF; private static final int FREE = -1; public CuckooSet(int capacity, double loadFactor, int insertRounds) { this.loadFactor = loadFactor; this.insertRounds = insertRounds; initializeCapacity(capacity, loadFactor); } public boolean add(int key) { if(contains(key)) { return false; } for(int i = 0; i < insertRounds; i++) { int h1 = h1(key); int register = keysT1[h1]; keysT1[h1] = key; if(register == FREE) { return true; } key = register; int h2 = h2(key); register = keysT2[h2]; keysT2[h2] = key; if(register == FREE) { return true; } key = register; } rehash(); return add(key); } public boolean contains(int key) { return keysT1[h1(key)] == key || keysT2[h2(key)] == key; } public int getRehashCounter() { return rehashCounter; } private void rehash() { int[] oldT1 = keysT1; int[] oldT2 = keysT2; int oldTableLength = tableLength; initializeCapacity(capacity * 2, loadFactor); for(int i = 0; i < oldTableLength; i++) { if(oldT1[i] != FREE) { add(oldT1[i]); } if(oldT2[i] != FREE) { add(oldT2[i]); } } rehashCounter++; } private void initializeCapacity(int capacity, double loadFactor) { this.capacity = capacity; tableLength = (int)(capacity / loadFactor); hashShift = 32 - (int)Math.ceil(Math.log(tableLength) / Math.log(2)); keysT1 = new int[tableLength]; keysT2 = new int[tableLength]; Arrays.fill(keysT1, FREE); Arrays.fill(keysT2, FREE); } private int h1(int key) { return ((int)( ((int)(key * H1) >> hashShift) & INT_MASK) ) % tableLength; } private int h2(int key) { return ((int)( ((int)(key * H2) >> hashShift) & INT_MASK) ) % tableLength; }}Cuckoo Filter的论文和PPT:Cuckoo Filter: Practically Better Than Bloom
http://users.cis.fiu.edu/~weiss/dsaajava3/code/CuckooHashTable.java