<s>
Cuckoo	B-Algorithm
hashing	I-Algorithm
is	O
a	O
scheme	O
in	O
computer	B-General_Concept
programming	I-General_Concept
for	O
resolving	O
hash	B-Algorithm
collisions	I-Algorithm
of	O
values	O
of	O
hash	B-Error_Name
functions	I-Error_Name
in	O
a	O
table	B-Algorithm
,	O
with	O
worst-case	B-General_Concept
constant	O
lookup	O
time	O
.	O
</s>
<s>
The	O
name	O
derives	O
from	O
the	O
behavior	O
of	O
some	O
species	O
of	O
cuckoo	O
,	O
where	O
the	O
cuckoo	O
chick	O
pushes	O
the	O
other	O
eggs	O
or	O
young	O
out	O
of	O
the	O
nest	O
when	O
it	O
hatches	O
in	O
a	O
variation	O
of	O
the	O
behavior	O
referred	O
to	O
as	O
brood	O
parasitism	O
;	O
analogously	O
,	O
inserting	O
a	O
new	O
key	B-Application
into	O
a	O
cuckoo	B-Algorithm
hashing	I-Algorithm
table	B-Algorithm
may	O
push	O
an	O
older	O
key	B-Application
to	O
a	O
different	O
location	O
in	O
the	O
table	B-Algorithm
.	O
</s>
<s>
Cuckoo	B-Algorithm
hashing	I-Algorithm
was	O
first	O
described	O
by	O
Rasmus	O
Pagh	O
and	O
Flemming	O
Friche	O
Rodler	O
in	O
a	O
2001	O
conference	O
paper	O
.	O
</s>
<s>
Cuckoo	B-Algorithm
hashing	I-Algorithm
is	O
a	O
form	O
of	O
open	B-Algorithm
addressing	I-Algorithm
in	O
which	O
each	O
non-empty	O
cell	O
of	O
a	O
hash	B-Algorithm
table	I-Algorithm
contains	O
a	O
key	B-Application
or	O
key	B-Application
–	I-Application
value	I-Application
pair	I-Application
.	O
</s>
<s>
A	O
hash	B-Error_Name
function	I-Error_Name
is	O
used	O
to	O
determine	O
the	O
location	O
for	O
each	O
key	B-Application
,	O
and	O
its	O
presence	O
in	O
the	O
table	B-Algorithm
(	O
or	O
the	O
value	O
associated	O
with	O
it	O
)	O
can	O
be	O
found	O
by	O
examining	O
that	O
cell	O
of	O
the	O
table	B-Algorithm
.	O
</s>
<s>
However	O
,	O
open	B-Algorithm
addressing	I-Algorithm
suffers	O
from	O
collisions	B-Algorithm
,	O
which	O
happens	O
when	O
more	O
than	O
one	O
key	B-Application
is	O
mapped	O
to	O
the	O
same	O
cell	O
.	O
</s>
<s>
The	O
basic	O
idea	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
is	O
to	O
resolve	O
collisions	B-Algorithm
by	O
using	O
two	O
hash	B-Error_Name
functions	I-Error_Name
instead	O
of	O
only	O
one	O
.	O
</s>
<s>
This	O
provides	O
two	O
possible	O
locations	O
in	O
the	O
hash	B-Algorithm
table	I-Algorithm
for	O
each	O
key	B-Application
.	O
</s>
<s>
In	O
one	O
of	O
the	O
commonly	O
used	O
variants	O
of	O
the	O
algorithm	O
,	O
the	O
hash	B-Algorithm
table	I-Algorithm
is	O
split	O
into	O
two	O
smaller	O
tables	O
of	O
equal	O
size	O
,	O
and	O
each	O
hash	B-Error_Name
function	I-Error_Name
provides	O
an	O
index	O
into	O
one	O
of	O
these	O
two	O
tables	O
.	O
</s>
<s>
It	O
is	O
also	O
possible	O
for	O
both	O
hash	B-Error_Name
functions	I-Error_Name
to	O
provide	O
indexes	O
into	O
a	O
single	O
table	B-Algorithm
.	O
</s>
<s>
Cuckoo	B-Algorithm
hashing	I-Algorithm
uses	O
two	O
hash	B-Algorithm
tables	I-Algorithm
,	O
and	O
and	O
assuming	O
be	O
the	O
length	O
of	O
each	O
tables	O
,	O
the	O
hash	B-Error_Name
functions	I-Error_Name
for	O
the	O
two	O
tables	O
is	O
defined	O
as	O
,	O
and	O
where	O
be	O
the	O
key	B-Application
and	O
be	O
the	O
set	O
whose	O
keys	O
are	O
stored	O
in	O
of	O
or	O
of	O
.	O
</s>
<s>
The	O
logical	O
or	O
(	O
)	O
denotes	O
that	O
,	O
the	O
value	O
of	O
the	O
key	B-Application
is	O
found	O
in	O
either	O
or	O
,	O
which	O
is	O
in	O
worst	B-General_Concept
case	I-General_Concept
.	O
</s>
<s>
Deletion	O
is	O
performed	O
in	O
since	O
there	O
is	O
n't	O
involvement	O
of	O
probing	O
—	O
not	O
considering	O
the	O
cost	O
of	O
shrinking	O
operation	O
if	O
table	B-Algorithm
is	O
too	O
sparse	O
.	O
</s>
<s>
Insertion	O
of	O
a	O
new	O
item	B-Application
,	O
the	O
first	O
step	O
involves	O
examining	O
if	O
the	O
slot	O
of	O
the	O
table	B-Algorithm
is	O
occupied	O
;	O
if	O
it	O
is	O
not	O
,	O
the	O
item	B-Application
is	O
inserted	O
at	O
that	O
cell	O
.	O
</s>
<s>
However	O
,	O
if	O
the	O
slot	O
is	O
occupied	O
,	O
the	O
preoccupied	O
item	B-Application
gets	O
removed	O
—	O
let	O
it	O
be	O
—	O
and	O
is	O
inserted	O
at	O
.	O
</s>
<s>
The	O
removed	O
item	B-Application
is	O
inserted	O
into	O
the	O
table	B-Algorithm
by	O
following	O
the	O
same	O
procedure	O
;	O
the	O
process	O
continues	O
until	O
an	O
empty	O
position	O
is	O
found	O
to	O
insert	O
the	O
key	B-Application
.	O
</s>
<s>
To	O
avoid	O
the	O
possible	O
infinite	B-Algorithm
iteration	I-Algorithm
in	O
the	O
process	O
loop	O
,	O
a	O
is	O
specified	O
such	O
that	O
if	O
the	O
iterations	B-Algorithm
exceeds	O
the	O
fixed	O
threshold	O
,	O
the	O
hash	B-Algorithm
tables	I-Algorithm
—	O
both	O
and	O
—	O
are	O
rehashed	O
with	O
newer	O
hash	B-Error_Name
functions	I-Error_Name
and	O
the	O
insertion	O
procedure	O
repeats	O
.	O
</s>
<s>
Following	O
is	O
a	O
pseudocode	B-Language
for	O
insertion	O
:	O
</s>
<s>
On	O
lines	O
10	O
and	O
15	O
,	O
the	O
"	O
cuckoo	O
approach	O
"	O
of	O
kicking	O
other	O
keys	O
—	O
which	O
was	O
preoccupied	O
at	O
—	O
takes	O
place	O
until	O
every	O
key	B-Application
has	O
its	O
own	O
"	O
nest	O
"	O
i.e.	O
</s>
<s>
the	O
item	B-Application
is	O
inserted	O
into	O
a	O
spot	O
on	O
either	O
one	O
of	O
the	O
two	O
tables	O
;	O
the	O
notation	O
expresses	O
the	O
process	O
of	O
swapping	O
.	O
</s>
<s>
Insertions	O
succeed	O
in	O
expected	O
constant	O
time	O
,	O
even	O
considering	O
the	O
possibility	O
of	O
having	O
to	O
rebuild	O
the	O
table	B-Algorithm
,	O
as	O
long	O
as	O
the	O
number	O
of	O
keys	O
is	O
kept	O
below	O
half	O
of	O
the	O
capacity	O
of	O
the	O
hash	B-Algorithm
table	I-Algorithm
,	O
i.e.	O
,	O
the	O
load	O
factor	O
is	O
below	O
50%	O
.	O
</s>
<s>
One	O
method	O
of	O
proving	O
this	O
uses	O
the	O
theory	O
of	O
random	O
graphs	O
:	O
one	O
may	O
form	O
an	O
undirected	O
graph	O
called	O
the	O
"	O
cuckoo	O
graph	O
"	O
that	O
has	O
a	O
vertex	O
for	O
each	O
hash	B-Algorithm
table	I-Algorithm
location	O
,	O
and	O
an	O
edge	O
for	O
each	O
hashed	O
value	O
,	O
with	O
the	O
endpoints	O
of	O
the	O
edge	O
being	O
the	O
two	O
possible	O
locations	O
of	O
the	O
value	O
.	O
</s>
<s>
Then	O
,	O
the	O
greedy	O
insertion	O
algorithm	O
for	O
adding	O
a	O
set	O
of	O
values	O
to	O
a	O
cuckoo	B-Algorithm
hash	I-Algorithm
table	I-Algorithm
succeeds	O
if	O
and	O
only	O
if	O
the	O
cuckoo	O
graph	O
for	O
this	O
set	O
of	O
values	O
is	O
a	O
pseudoforest	O
,	O
a	O
graph	O
with	O
at	O
most	O
one	O
cycle	O
in	O
each	O
of	O
its	O
connected	O
components	O
.	O
</s>
<s>
Any	O
vertex-induced	O
subgraph	O
with	O
more	O
edges	O
than	O
vertices	O
corresponds	O
to	O
a	O
set	O
of	O
keys	O
for	O
which	O
there	O
are	O
an	O
insufficient	O
number	O
of	O
slots	O
in	O
the	O
hash	B-Algorithm
table	I-Algorithm
.	O
</s>
<s>
When	O
the	O
hash	B-Error_Name
function	I-Error_Name
is	O
chosen	O
randomly	O
,	O
the	O
cuckoo	O
graph	O
is	O
a	O
random	O
graph	O
in	O
the	O
Erdős	O
–	O
Rényi	O
model	O
.	O
</s>
<s>
With	O
high	O
probability	O
,	O
for	O
load	O
factor	O
less	O
than	O
1/2	O
(	O
corresponding	O
to	O
a	O
random	O
graph	O
in	O
which	O
the	O
ratio	O
of	O
the	O
number	O
of	O
edges	O
to	O
the	O
number	O
of	O
vertices	O
is	O
bounded	O
below	O
1/2	O
)	O
,	O
the	O
graph	O
is	O
a	O
pseudoforest	O
and	O
the	O
cuckoo	B-Algorithm
hashing	I-Algorithm
algorithm	O
succeeds	O
in	O
placing	O
all	O
keys	O
.	O
</s>
<s>
Since	O
a	O
theoretical	O
random	O
hash	B-Error_Name
function	I-Error_Name
requires	O
too	O
much	O
space	O
for	O
practical	O
usage	O
,	O
an	O
important	O
theoretical	O
question	O
is	O
which	O
practical	O
hash	B-Error_Name
functions	I-Error_Name
suffice	O
for	O
Cuckoo	B-Algorithm
hashing	I-Algorithm
.	O
</s>
<s>
One	O
approach	O
is	O
to	O
use	O
k-independent	B-Error_Name
hashing	I-Error_Name
.	O
</s>
<s>
Another	O
approach	O
is	O
to	O
use	O
Tabulation	B-Algorithm
hashing	I-Algorithm
,	O
which	O
is	O
not	O
6-independent	O
,	O
but	O
was	O
shown	O
in	O
2012	O
to	O
have	O
other	O
properties	O
sufficient	O
for	O
Cuckoo	B-Algorithm
hashing	I-Algorithm
.	O
</s>
<s>
A	O
third	O
approach	O
from	O
2014	O
is	O
to	O
slightly	O
modify	O
the	O
cuckoo	O
hashtable	B-Algorithm
with	O
a	O
so-called	O
stash	O
,	O
which	O
makes	O
it	O
possible	O
to	O
use	O
nothing	O
more	O
than	O
2-independent	O
hash	B-Error_Name
functions	I-Error_Name
.	O
</s>
<s>
In	O
practice	O
,	O
cuckoo	B-Algorithm
hashing	I-Algorithm
is	O
about	O
20	O
–	O
30%	O
slower	O
than	O
linear	B-Algorithm
probing	I-Algorithm
,	O
which	O
is	O
the	O
fastest	O
of	O
the	O
common	O
approaches	O
.	O
</s>
<s>
The	O
reason	O
is	O
that	O
cuckoo	B-Algorithm
hashing	I-Algorithm
often	O
causes	O
two	O
cache	B-General_Concept
misses	O
per	O
search	O
,	O
to	O
check	O
the	O
two	O
locations	O
where	O
a	O
key	B-Application
might	O
be	O
stored	O
,	O
while	O
linear	B-Algorithm
probing	I-Algorithm
usually	O
causes	O
only	O
one	O
cache	B-General_Concept
miss	O
per	O
search	O
.	O
</s>
<s>
However	O
,	O
because	O
of	O
its	O
worst	B-General_Concept
case	I-General_Concept
guarantees	O
on	O
search	O
time	O
,	O
cuckoo	B-Algorithm
hashing	I-Algorithm
can	O
still	O
be	O
valuable	O
when	O
real-time	B-General_Concept
response	I-General_Concept
rates	I-General_Concept
are	O
required	O
.	O
</s>
<s>
One	O
advantage	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
is	O
its	O
link-list	O
free	O
property	O
,	O
which	O
fits	O
GPU	O
processing	O
well	O
.	O
</s>
<s>
The	O
following	O
hash	B-Error_Name
functions	I-Error_Name
are	O
given	O
:	O
</s>
<s>
Each	O
column	O
corresponds	O
to	O
the	O
state	O
of	O
the	O
two	O
hash	B-Algorithm
tables	I-Algorithm
over	O
time	O
.	O
</s>
<s>
In	O
the	O
last	O
row	O
of	O
the	O
table	B-Algorithm
we	O
find	O
the	O
same	O
initial	O
situation	O
as	O
at	O
the	O
beginning	O
again	O
.	O
</s>
<s>
Several	O
variations	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
have	O
been	O
studied	O
,	O
primarily	O
with	O
the	O
aim	O
of	O
improving	O
its	O
space	O
usage	O
by	O
increasing	O
the	O
load	O
factor	O
that	O
it	O
can	O
tolerate	O
to	O
a	O
number	O
greater	O
than	O
the	O
50%	O
threshold	O
of	O
the	O
basic	O
algorithm	O
.	O
</s>
<s>
Some	O
of	O
these	O
methods	O
can	O
also	O
be	O
used	O
to	O
reduce	O
the	O
failure	O
rate	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
,	O
causing	O
rebuilds	O
of	O
the	O
data	O
structure	O
to	O
be	O
much	O
less	O
frequent	O
.	O
</s>
<s>
Generalizations	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
that	O
use	O
more	O
than	O
two	O
alternative	O
hash	B-Error_Name
functions	I-Error_Name
can	O
be	O
expected	O
to	O
utilize	O
a	O
larger	O
part	O
of	O
the	O
capacity	O
of	O
the	O
hash	B-Algorithm
table	I-Algorithm
efficiently	O
while	O
sacrificing	O
some	O
lookup	O
and	O
insertion	O
speed	O
.	O
</s>
<s>
Using	O
just	O
three	O
hash	B-Error_Name
functions	I-Error_Name
increases	O
the	O
load	O
to	O
91%	O
.	O
</s>
<s>
Another	O
generalization	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
,	O
called	O
blocked	O
cuckoo	B-Algorithm
hashing	I-Algorithm
consists	O
in	O
using	O
more	O
than	O
one	O
key	B-Application
per	O
bucket	O
.	O
</s>
<s>
Another	O
variation	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
that	O
has	O
been	O
studied	O
is	O
cuckoo	B-Algorithm
hashing	I-Algorithm
with	O
a	O
stash	O
.	O
</s>
<s>
The	O
stash	O
,	O
in	O
this	O
data	O
structure	O
,	O
is	O
an	O
array	O
of	O
a	O
constant	O
number	O
of	O
keys	O
,	O
used	O
to	O
store	O
keys	O
that	O
cannot	O
successfully	O
be	O
inserted	O
into	O
the	O
main	O
hash	B-Algorithm
table	I-Algorithm
of	O
the	O
structure	O
.	O
</s>
<s>
This	O
modification	O
reduces	O
the	O
failure	O
rate	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
to	O
an	O
inverse-polynomial	O
function	O
with	O
an	O
exponent	O
that	O
can	O
be	O
made	O
arbitrarily	O
large	O
by	O
increasing	O
the	O
stash	O
size	O
.	O
</s>
<s>
A	O
stash	O
can	O
be	O
used	O
in	O
combination	O
with	O
more	O
than	O
two	O
hash	B-Error_Name
functions	I-Error_Name
or	O
with	O
blocked	O
cuckoo	B-Algorithm
hashing	I-Algorithm
to	O
achieve	O
both	O
high	O
load	O
factors	O
and	O
small	O
failure	O
rates	O
.	O
</s>
<s>
The	O
analysis	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
with	O
a	O
stash	O
extends	O
to	O
practical	O
hash	B-Error_Name
functions	I-Error_Name
,	O
not	O
just	O
to	O
the	O
random	O
hash	B-Error_Name
function	I-Error_Name
model	O
commonly	O
used	O
in	O
theoretical	O
analysis	O
of	O
hashing	O
.	O
</s>
<s>
Some	O
people	O
recommend	O
a	O
simplified	O
generalization	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
called	O
skewed-associative	O
cache	B-General_Concept
in	O
some	O
CPU	B-General_Concept
caches	I-General_Concept
.	O
</s>
<s>
Another	O
variation	O
of	O
a	O
cuckoo	B-Algorithm
hash	I-Algorithm
table	I-Algorithm
,	O
called	O
a	O
cuckoo	B-Algorithm
filter	I-Algorithm
,	O
replaces	O
the	O
stored	O
keys	O
of	O
a	O
cuckoo	B-Algorithm
hash	I-Algorithm
table	I-Algorithm
with	O
much	O
shorter	O
fingerprints	O
,	O
computed	O
by	O
applying	O
another	O
hash	B-Error_Name
function	I-Error_Name
to	O
the	O
keys	O
.	O
</s>
<s>
In	O
order	O
to	O
allow	O
these	O
fingerprints	O
to	O
be	O
moved	O
around	O
within	O
the	O
cuckoo	B-Algorithm
filter	I-Algorithm
,	O
without	O
knowing	O
the	O
keys	O
that	O
they	O
came	O
from	O
,	O
the	O
two	O
locations	O
of	O
each	O
fingerprint	O
may	O
be	O
computed	O
from	O
each	O
other	O
by	O
a	O
bitwise	O
exclusive	O
or	O
operation	O
with	O
the	O
fingerprint	O
,	O
or	O
with	O
a	O
hash	B-Error_Name
of	O
the	O
fingerprint	O
.	O
</s>
<s>
This	O
data	O
structure	O
forms	O
an	O
approximate	O
set	O
membership	O
data	O
structure	O
with	O
much	O
the	O
same	O
properties	O
as	O
a	O
Bloom	B-Algorithm
filter	I-Algorithm
:	O
it	O
can	O
store	O
the	O
members	O
of	O
a	O
set	O
of	O
keys	O
,	O
and	O
test	O
whether	O
a	O
query	O
key	B-Application
is	O
a	O
member	O
,	O
with	O
some	O
chance	O
of	O
false	O
positives	O
(	O
queries	O
that	O
are	O
incorrectly	O
reported	O
as	O
being	O
part	O
of	O
the	O
set	O
)	O
but	O
no	O
false	O
negatives	O
.	O
</s>
<s>
However	O
,	O
it	O
improves	O
on	O
a	O
Bloom	B-Algorithm
filter	I-Algorithm
in	O
multiple	O
respects	O
:	O
its	O
memory	O
usage	O
is	O
smaller	O
by	O
a	O
constant	O
factor	O
,	O
it	O
has	O
better	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
,	O
and	O
(	O
unlike	O
Bloom	B-Algorithm
filters	I-Algorithm
)	O
it	O
allows	O
for	O
fast	O
deletion	O
of	O
set	O
elements	O
with	O
no	O
additional	O
storage	O
penalty	O
.	O
</s>
<s>
has	O
shown	O
that	O
cuckoo	B-Algorithm
hashing	I-Algorithm
is	O
much	O
faster	O
than	O
chained	O
hashing	O
for	O
small	O
,	O
cache-resident	O
hash	B-Algorithm
tables	I-Algorithm
on	O
modern	O
processors	O
.	O
</s>
<s>
Kenneth	O
Ross	O
has	O
shown	O
bucketized	O
versions	O
of	O
cuckoo	B-Algorithm
hashing	I-Algorithm
(	O
variants	O
that	O
use	O
buckets	O
that	O
contain	O
more	O
than	O
one	O
key	B-Application
)	O
to	O
be	O
faster	O
than	O
conventional	O
methods	O
also	O
for	O
large	O
hash	B-Algorithm
tables	I-Algorithm
,	O
when	O
space	O
utilization	O
is	O
high	O
.	O
</s>
<s>
The	O
performance	O
of	O
the	O
bucketized	O
cuckoo	B-Algorithm
hash	I-Algorithm
table	I-Algorithm
was	O
investigated	O
further	O
by	O
Askitis	O
,	O
</s>
<s>
A	O
survey	O
by	O
Mitzenmacher	O
presents	O
open	O
problems	O
related	O
to	O
cuckoo	B-Algorithm
hashing	I-Algorithm
as	O
of	O
2009	O
.	O
</s>
