evicting the first item did not perform well in experiments evicting the last item did not perform well in experiments evicting the items in sequence ( the first eviction uses hash function the next uses hash function etc did not perform well in experiments evicting the item purely randomly did not perform well in experimentsin particularwith only two hash functionsit tended to create cycles to alleviate the last problemwe maintain the last position that was evictedand if our random item was the last evicted itemwe select new random item this will loop forever if used with two hash functionsand both hash functions happen to probe to the same locationand that location was prior evictionso we limit the loop to five iterations (deliberately using an odd numberthe code for expand and rehash is shown in figure expand creates larger array but keeps the same hash functions the zero-parameter rehash leaves the array size unchanged but creates new array that is populated with newly chosen hash functions void expandrehashstatic_castarray sizemax_load )void rehashhashfunctions generatenewfunctions)rehasharray size)void rehashint newsize vector oldarray array/create new double-sizedempty table array resizenextprimenewsize )forauto entry array entry isactive false/copy table over currentsize forauto entry oldarray ifentry isactive insertstd::moveentry element )figure rehashing and expanding code for cuckoo hash tables