<s>
A	O
concurrent	B-Algorithm
hash-trie	I-Algorithm
or	O
Ctrie	B-Algorithm
is	O
a	O
concurrent	O
thread-safe	B-Operating_System
lock-free	B-Operating_System
implementation	O
of	O
a	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
trie	I-Data_Structure
.	O
</s>
<s>
It	O
is	O
the	O
first	O
known	O
concurrent	O
data-structure	O
that	O
supports	O
O(1 )	O
,	O
atomic	O
,	O
lock-free	B-Operating_System
snapshots	O
.	O
</s>
<s>
The	O
Ctrie	B-Algorithm
data	O
structure	O
is	O
a	O
non-blocking	O
concurrent	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
trie	I-Data_Structure
based	O
on	O
single-word	O
compare-and-swap	O
instructions	O
in	O
a	O
shared-memory	O
system	O
.	O
</s>
<s>
Just	O
like	O
the	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
trie	I-Data_Structure
,	O
it	O
uses	O
the	O
entire	O
32-bit	O
space	O
for	O
hash	O
values	O
thus	O
having	O
low	O
risk	O
of	O
hashcode	O
collisions	O
.	O
</s>
<s>
The	O
figure	O
above	O
illustrates	O
the	O
Ctrie	B-Algorithm
insert	O
operation	O
.	O
</s>
<s>
If	O
two	O
hashcodes	O
of	O
the	O
keys	O
in	O
the	O
Ctrie	B-Algorithm
collide	O
as	O
is	O
the	O
case	O
with	O
k2	O
and	O
k3	O
,	O
the	O
Ctrie	B-Algorithm
must	O
be	O
extended	O
with	O
at	O
least	O
one	O
more	O
level	O
-	O
trie	O
D	O
has	O
a	O
new	O
indirection	O
node	O
I2	O
with	O
a	O
new	O
node	O
C2	O
which	O
holds	O
both	O
colliding	O
keys	O
.	O
</s>
<s>
The	O
Ctrie	B-Algorithm
is	O
defined	O
by	O
the	O
pointer	O
to	O
the	O
root	O
indirection	O
node	O
(	O
or	O
a	O
root	O
I-node	O
)	O
.	O
</s>
<s>
The	O
following	O
types	O
of	O
nodes	O
are	O
defined	O
for	O
the	O
Ctrie	B-Algorithm
:	O
</s>
<s>
Note	O
that	O
the	O
operations	O
treat	O
only	O
the	O
I-nodes	O
as	O
mutable	O
nodes	O
-	O
all	O
other	O
nodes	O
are	O
never	O
changed	O
after	O
being	O
created	O
and	O
added	O
to	O
the	O
Ctrie	B-Algorithm
.	O
</s>
<s>
Below	O
is	O
an	O
illustration	O
of	O
the	O
pseudocode	B-Language
of	O
the	O
insert	O
operation	O
:	O
</s>
<s>
Note	O
that	O
the	O
insert	O
operation	O
above	O
is	O
tail-recursive	B-Language
,	O
so	O
it	O
can	O
be	O
rewritten	O
as	O
a	O
while	O
loop	O
.	O
</s>
<s>
Other	O
operations	O
are	O
described	O
in	O
more	O
detail	O
in	O
the	O
original	O
paper	O
on	O
Ctries	B-Algorithm
.	O
</s>
<s>
The	O
data-structure	O
has	O
been	O
proven	O
to	O
be	O
correct	O
-	O
Ctrie	B-Algorithm
operations	O
have	O
been	O
shown	O
to	O
have	O
the	O
atomicity	O
,	O
linearizability	O
and	O
lock-freedom	O
properties	O
.	O
</s>
<s>
Ctries	B-Algorithm
have	O
been	O
shown	O
to	O
be	O
comparable	O
in	O
performance	O
with	O
concurrent	O
skip	O
lists	O
,	O
concurrent	O
hash	B-Algorithm
tables	I-Algorithm
and	O
similar	O
data	O
structures	O
in	O
terms	O
of	O
the	O
lookup	O
operation	O
,	O
being	O
slightly	O
slower	O
than	O
hash	B-Algorithm
tables	I-Algorithm
and	O
faster	O
than	O
skip	O
lists	O
due	O
to	O
the	O
lower	O
level	O
of	O
indirections	O
.	O
</s>
<s>
However	O
,	O
they	O
are	O
far	O
more	O
scalable	O
than	O
most	O
concurrent	O
hash	B-Algorithm
tables	I-Algorithm
where	O
the	O
insertions	O
are	O
concerned	O
.	O
</s>
<s>
Most	O
concurrent	O
hash	B-Algorithm
tables	I-Algorithm
are	O
bad	O
at	O
conserving	O
memory	O
-	O
when	O
the	O
keys	O
are	O
removed	O
from	O
the	O
hash	B-Algorithm
table	I-Algorithm
,	O
the	O
underlying	O
array	O
is	O
not	O
shrunk	O
.	O
</s>
<s>
Ctries	B-Algorithm
have	O
the	O
property	O
that	O
the	O
allocated	O
memory	O
is	O
always	O
a	O
function	O
of	O
only	O
the	O
current	O
number	O
of	O
keys	O
in	O
the	O
data-structure	O
.	O
</s>
<s>
Ctries	B-Algorithm
have	O
logarithmic	O
complexity	O
bounds	O
of	O
the	O
basic	O
operations	O
,	O
albeit	O
with	O
a	O
low	O
constant	O
factor	O
due	O
to	O
the	O
high	O
branching	O
level	O
(	O
usually	O
32	O
)	O
.	O
</s>
<s>
Ctries	B-Algorithm
support	O
a	O
lock-free	B-Operating_System
,	O
linearizable	O
,	O
constant-time	O
snapshot	O
operation	O
,	O
based	O
on	O
the	O
insight	O
obtained	O
from	O
persistent	B-Application
data	I-Application
structures	I-Application
.	O
</s>
<s>
The	O
snapshot	O
operation	O
allows	O
implementing	O
lock-free	B-Operating_System
,	O
linearizable	O
iterator	O
,	O
size	O
and	O
clear	O
operations	O
-	O
existing	O
concurrent	O
data-structures	O
have	O
implementations	O
which	O
either	O
use	O
global	O
locks	O
or	O
are	O
correct	O
only	O
given	O
that	O
there	O
are	O
no	O
concurrent	O
modifications	O
to	O
the	O
data-structure	O
.	O
</s>
<s>
In	O
particular	O
,	O
Ctries	B-Algorithm
have	O
an	O
O(1 )	O
iterator	O
creation	O
operation	O
,	O
O(1 )	O
clear	O
operation	O
,	O
O(1 )	O
duplicate	O
operation	O
and	O
an	O
amortized	B-General_Concept
O(logn )	O
size	O
retrieval	O
operation	O
.	O
</s>
<s>
Most	O
concurrent	O
data	O
structures	O
require	O
dynamic	O
memory	O
allocation	O
,	O
and	O
lock-free	B-Operating_System
concurrent	O
data	O
structures	O
rely	O
on	O
garbage	O
collection	O
on	O
most	O
platforms	O
.	O
</s>
<s>
The	O
current	O
implementation	O
of	O
the	O
Ctrie	B-Algorithm
is	O
written	O
for	O
the	O
JVM	O
,	O
where	O
garbage	O
collection	O
is	O
provided	O
by	O
the	O
platform	O
itself	O
.	O
</s>
<s>
While	O
it	O
's	O
possible	O
to	O
keep	O
a	O
concurrent	O
memory	O
pool	O
for	O
the	O
nodes	O
shared	O
by	O
all	O
instances	O
of	O
Ctries	B-Algorithm
in	O
an	O
application	O
or	O
use	O
reference	O
counting	O
to	O
properly	O
deallocate	O
nodes	O
,	O
the	O
only	O
implementation	O
so	O
far	O
to	O
deal	O
with	O
manual	O
memory	O
management	O
of	O
nodes	O
used	O
in	O
Ctries	B-Algorithm
is	O
the	O
common-lisp	O
implementation	O
,	O
which	O
implements	O
several	O
stop-and-copy	O
and	O
mark-and-sweep	O
garbage	O
collection	O
techniques	O
for	O
persistent	O
,	O
memory-mapped	O
storage	O
.	O
</s>
<s>
A	O
Ctrie	B-Algorithm
implementation	O
in	O
Rust	O
makes	O
use	O
of	O
hazard	O
pointers	O
for	O
this	O
purpose	O
.	O
</s>
<s>
A	O
Ctrie	B-Algorithm
implementation	O
for	O
Scala	B-Application
2.9.x	O
is	O
available	O
on	O
GitHub	O
.	O
</s>
<s>
It	O
is	O
a	O
mutable	O
thread-safe	B-Operating_System
implementation	O
which	O
ensures	O
progress	O
and	O
supports	O
lock-free	B-Operating_System
,	O
linearizable	O
,	O
O(1 )	O
snapshots	O
.	O
</s>
<s>
A	O
data-structure	O
similar	O
to	O
Ctries	B-Algorithm
has	O
been	O
used	O
in	O
ScalaSTM	O
,	O
a	O
software	B-Operating_System
transactional	I-Operating_System
memory	I-Operating_System
library	O
for	O
the	O
JVM	O
.	O
</s>
<s>
The	O
Scala	B-Application
standard	O
library	O
(	O
as	O
of	O
2.13.x	O
)	O
includes	O
a	O
Ctries	B-Algorithm
implementation	O
since	O
February	O
2012	O
.	O
</s>
<s>
CL-CTRIE	O
is	O
a	O
Common	O
Lisp	O
implementation	O
available	O
on	O
GitHub	O
.	O
</s>
<s>
An	O
insert-only	O
Ctrie	B-Algorithm
variant	O
has	O
been	O
used	O
for	O
tabling	O
in	O
Prolog	O
programs	O
.	O
</s>
<s>
A	O
Rust	O
implementation	O
uses	O
hazard	O
pointers	O
in	O
its	O
implementation	O
to	O
achieve	O
lock-free	B-Operating_System
synchronization	O
.	O
</s>
<s>
Both	O
a	O
managed	O
and	O
an	O
unmanaged	O
C++	O
version	O
of	O
Ctrie	B-Algorithm
was	O
implemented	O
.	O
</s>
<s>
Ctries	B-Algorithm
were	O
first	O
described	O
in	O
2011	O
by	O
Aleksandar	O
Prokopec	O
.	O
</s>
<s>
Ctrie	B-Algorithm
is	O
a	O
non-blocking	O
concurrent	O
shared-memory	O
hash	O
trie	O
based	O
on	O
single-word	O
compare-and-swap	O
instructions	O
.	O
</s>
<s>
In	O
2012	O
,	O
a	O
revised	O
version	O
of	O
the	O
Ctrie	B-Algorithm
data	O
structure	O
was	O
published	O
,	O
simplifying	O
the	O
data	O
structure	O
and	O
introducing	O
an	O
optional	O
constant-time	O
,	O
lock-free	B-Operating_System
,	O
atomic	O
snapshot	O
operation	O
.	O
</s>
<s>
In	O
2018	O
,	O
the	O
closely	O
related	O
Cache-Trie	O
data	O
structure	O
was	O
proposed	O
,	O
which	O
augmented	O
Ctries	B-Algorithm
with	O
an	O
auxiliary	O
,	O
quiescently	O
consistent	O
cache	O
data	O
structure	O
.	O
</s>
<s>
This	O
"	O
cache	O
"	O
is	O
a	O
hash-table-like	O
entity	O
that	O
makes	O
a	O
best	O
effort	O
to	O
"	O
guess	O
"	O
the	O
appropriate	O
node	O
on	O
a	O
deeper	O
level	O
of	O
the	O
trie	O
,	O
and	O
is	O
maintained	O
in	O
a	O
way	O
such	O
that	O
it	O
's	O
as	O
close	O
as	O
possible	O
to	O
the	O
level	O
where	O
most	O
of	O
the	O
trie	O
's	O
elements	O
are	O
.	O
</s>
<s>
Cache	O
tries	O
were	O
shown	O
to	O
have	O
amortized	B-General_Concept
expected	O
O(1 )	O
complexity	O
of	O
all	O
the	O
basic	O
operations	O
.	O
</s>
