<s>
In	O
computing	O
,	O
a	O
persistent	B-Application
data	I-Application
structure	I-Application
or	O
not	O
ephemeral	B-Application
data	I-Application
structure	I-Application
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
always	O
preserves	O
the	O
previous	O
version	O
of	O
itself	O
when	O
it	O
is	O
modified	O
.	O
</s>
<s>
Such	O
data	B-General_Concept
structures	I-General_Concept
are	O
effectively	O
immutable	B-Application
,	O
as	O
their	O
operations	O
do	O
not	O
(	O
visibly	O
)	O
update	O
the	O
structure	O
in-place	O
,	O
but	O
instead	O
always	O
yield	O
a	O
new	O
updated	O
structure	O
.	O
</s>
<s>
A	O
data	B-General_Concept
structure	I-General_Concept
is	O
partially	O
persistent	O
if	O
all	O
versions	O
can	O
be	O
accessed	O
but	O
only	O
the	O
newest	O
version	O
can	O
be	O
modified	O
.	O
</s>
<s>
The	O
data	B-General_Concept
structure	I-General_Concept
is	O
fully	O
persistent	O
if	O
every	O
version	O
can	O
be	O
both	O
accessed	O
and	O
modified	O
.	O
</s>
<s>
If	O
there	O
is	O
also	O
a	O
meld	O
or	O
merge	O
operation	O
that	O
can	O
create	O
a	O
new	O
version	O
from	O
two	O
previous	O
versions	O
,	O
the	O
data	B-General_Concept
structure	I-General_Concept
is	O
called	O
confluently	O
persistent	O
.	O
</s>
<s>
These	O
types	B-General_Concept
of	I-General_Concept
data	I-General_Concept
structures	I-General_Concept
are	O
particularly	O
common	O
in	O
logical	B-Language
and	O
functional	B-Language
programming	I-Language
,	O
as	O
languages	O
in	O
those	O
paradigms	O
discourage	O
(	O
or	O
fully	O
forbid	O
)	O
the	O
use	O
of	O
mutable	B-Application
data	O
.	O
</s>
<s>
In	O
the	O
partial	O
persistence	O
model	O
,	O
a	O
programmer	O
may	O
query	O
any	O
previous	O
version	O
of	O
a	O
data	B-General_Concept
structure	I-General_Concept
,	O
but	O
may	O
only	O
update	O
the	O
latest	O
version	O
.	O
</s>
<s>
This	O
implies	O
a	O
linear	O
ordering	O
among	O
each	O
version	O
of	O
the	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
In	O
the	O
fully	O
persistent	O
model	O
,	O
both	O
updates	O
and	O
queries	O
are	O
allowed	O
on	O
any	O
version	O
of	O
the	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
In	O
some	O
cases	O
the	O
performance	O
characteristics	O
of	O
querying	O
or	O
updating	O
older	O
versions	O
of	O
a	O
data	B-General_Concept
structure	I-General_Concept
may	O
be	O
allowed	O
to	O
degrade	O
,	O
as	O
is	O
true	O
with	O
the	O
Rope	B-Data_Structure
data	I-Data_Structure
structure	I-Data_Structure
.	O
</s>
<s>
In	O
addition	O
,	O
a	O
data	B-General_Concept
structure	I-General_Concept
can	O
be	O
referred	O
to	O
as	O
confluently	O
persistent	O
if	O
,	O
in	O
addition	O
to	O
being	O
fully	O
persistent	O
,	O
two	O
versions	O
of	O
the	O
same	O
data	B-General_Concept
structure	I-General_Concept
can	O
be	O
combined	O
to	O
form	O
a	O
new	O
version	O
which	O
is	O
still	O
fully	O
persistent	O
.	O
</s>
<s>
One	O
method	O
for	O
creating	O
a	O
persistent	B-Application
data	I-Application
structure	I-Application
is	O
to	O
use	O
a	O
platform	O
provided	O
ephemeral	B-Application
data	I-Application
structure	I-Application
such	O
as	O
an	O
array	B-Data_Structure
to	O
store	O
the	O
data	O
in	O
the	O
data	B-General_Concept
structure	I-General_Concept
and	O
copy	O
the	O
entirety	O
of	O
that	O
data	B-General_Concept
structure	I-General_Concept
using	O
copy-on-write	B-Language
semantics	I-Language
for	O
any	O
updates	O
to	O
the	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
This	O
is	O
an	O
inefficient	O
technique	O
because	O
the	O
entire	O
backing	O
data	B-General_Concept
structure	I-General_Concept
must	O
be	O
copied	O
for	O
each	O
write	O
,	O
leading	O
to	O
worst	O
case	O
O( n·m	O
)	O
performance	O
characteristics	O
for	O
m	O
modifications	O
of	O
an	O
array	B-Data_Structure
of	O
size	O
n	O
.	O
</s>
<s>
This	O
is	O
an	O
amortized	B-General_Concept
time	I-General_Concept
bound	O
,	O
assuming	O
modification	O
history	O
is	O
stored	O
in	O
a	O
growable	B-Data_Structure
array	I-Data_Structure
.	O
</s>
<s>
At	O
access	B-General_Concept
time	I-General_Concept
,	O
the	O
right	O
version	O
at	O
each	O
node	O
must	O
be	O
found	O
as	O
the	O
structure	O
is	O
traversed	O
.	O
</s>
<s>
If	O
"	O
m	O
"	O
modifications	O
were	O
to	O
be	O
made	O
,	O
then	O
each	O
access	O
operation	O
would	O
have	O
O(log m )	O
slowdown	O
resulting	O
from	O
the	O
cost	O
of	O
finding	O
the	O
nearest	O
modification	O
in	O
the	O
array	B-Data_Structure
.	O
</s>
<s>
These	O
changes	O
must	O
then	O
be	O
cascaded	B-Data_Structure
back	O
through	O
the	O
data	B-General_Concept
structure	I-General_Concept
:	O
all	O
nodes	O
that	O
pointed	O
to	O
the	O
old	O
node	O
must	O
be	O
modified	O
to	O
point	O
to	O
the	O
new	O
node	O
instead	O
.	O
</s>
<s>
These	O
modifications	O
cause	O
more	O
cascading	O
changes	O
,	O
and	O
so	O
on	O
,	O
until	O
the	O
root	B-Application
node	I-Application
is	O
reached	O
.	O
</s>
<s>
With	O
m	O
modifications	O
,	O
this	O
costs	O
O(log m )	O
additive	O
lookup	B-Data_Structure
time	O
.	O
</s>
<s>
Modification	O
time	O
and	O
space	O
are	O
bounded	O
by	O
the	O
size	O
of	O
the	O
longest	O
path	O
in	O
the	O
data	B-General_Concept
structure	I-General_Concept
and	O
the	O
cost	O
of	O
the	O
update	O
in	O
the	O
ephemeral	B-Application
data	I-Application
structure	I-Application
.	O
</s>
<s>
In	O
a	O
Balanced	O
Binary	B-Language
Search	I-Language
Tree	I-Language
without	O
parent	O
pointers	O
the	O
worst	O
case	O
modification	O
time	O
complexity	O
is	O
O( log	O
n	O
+	O
update	O
cost	O
)	O
.	O
</s>
<s>
However	O
,	O
in	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
the	O
worst	O
case	O
modification	O
time	O
complexity	O
is	O
O( n	O
+	O
update	O
cost	O
)	O
.	O
</s>
<s>
Whenever	O
a	O
node	O
is	O
accessed	O
,	O
the	O
modification	O
box	O
is	O
checked	O
,	O
and	O
its	O
timestamp	O
is	O
compared	O
against	O
the	O
access	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
(	O
The	O
access	B-General_Concept
time	I-General_Concept
specifies	O
the	O
version	O
of	O
the	O
data	B-General_Concept
structure	I-General_Concept
being	O
considered	O
.	O
)	O
</s>
<s>
If	O
the	O
modification	O
box	O
is	O
empty	O
,	O
or	O
the	O
access	B-General_Concept
time	I-General_Concept
is	O
before	O
the	O
modification	O
time	O
,	O
then	O
the	O
modification	O
box	O
is	O
ignored	O
and	O
only	O
the	O
normal	O
part	O
of	O
the	O
node	O
is	O
considered	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
if	O
the	O
access	B-General_Concept
time	I-General_Concept
is	O
after	O
the	O
modification	O
time	O
,	O
then	O
the	O
value	O
in	O
the	O
modification	O
box	O
is	O
used	O
,	O
overriding	O
that	O
value	O
in	O
the	O
node	O
.	O
</s>
<s>
Finally	O
,	O
this	O
change	O
is	O
cascaded	B-Data_Structure
to	O
the	O
node	O
's	O
parent	O
,	O
just	O
like	O
path	O
copying	O
.	O
</s>
<s>
If	O
the	O
node	O
has	O
no	O
it	O
's	O
the	O
root	O
—	O
it	O
is	O
added	O
the	O
new	O
root	O
to	O
a	O
sorted	B-Data_Structure
array	I-Data_Structure
of	O
roots	O
.	O
)	O
</s>
<s>
With	O
this	O
algorithm	O
,	O
given	O
any	O
time	O
t	O
,	O
at	O
most	O
one	O
modification	O
box	O
exists	O
in	O
the	O
data	B-General_Concept
structure	I-General_Concept
with	O
time	O
t	O
.	O
Thus	O
,	O
a	O
modification	O
at	O
time	O
t	O
splits	O
the	O
tree	B-Application
into	O
three	O
parts	O
:	O
one	O
part	O
contains	O
the	O
data	O
from	O
before	O
time	O
t	O
,	O
one	O
part	O
contains	O
the	O
data	O
from	O
after	O
time	O
t	O
,	O
and	O
one	O
part	O
was	O
unaffected	O
by	O
the	O
modification	O
.	O
</s>
<s>
Time	O
and	O
space	O
for	O
modifications	O
require	O
amortized	B-General_Concept
analysis	I-General_Concept
.	O
</s>
<s>
A	O
modification	O
takes	O
O(1 )	O
amortized	B-General_Concept
space	O
,	O
and	O
O(1 )	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
To	O
see	O
why	O
,	O
use	O
a	O
potential	B-General_Concept
function	I-General_Concept
ϕ	O
,	O
where	O
ϕ(T )	O
is	O
the	O
number	O
of	O
full	O
live	O
nodes	O
in	O
T	O
.	O
</s>
<s>
Each	O
costs	O
O(1 )	O
space	O
and	O
time	O
,	O
but	O
decreases	O
the	O
potential	B-General_Concept
function	I-General_Concept
by	O
one	O
.	O
</s>
<s>
(	O
First	O
,	O
the	O
node	O
to	O
be	O
copied	O
must	O
be	O
full	O
and	O
live	O
,	O
so	O
it	O
contributes	O
to	O
the	O
potential	B-General_Concept
function	I-General_Concept
.	O
</s>
<s>
The	O
potential	B-General_Concept
function	I-General_Concept
will	O
only	O
drop	O
,	O
however	O
,	O
if	O
the	O
old	O
node	O
is	O
n't	O
reachable	O
in	O
the	O
new	O
tree	B-Application
.	O
</s>
<s>
But	O
it	O
is	O
known	O
that	O
it	O
is	O
n't	O
reachable	O
in	O
the	O
new	O
tree	B-Application
—	O
the	O
next	O
step	O
in	O
the	O
algorithm	O
will	O
be	O
to	O
modify	O
the	O
node	O
's	O
parent	O
to	O
point	O
at	O
the	O
copy	O
.	O
</s>
<s>
Path	O
copying	O
is	O
one	O
of	O
the	O
simple	O
methods	O
to	O
achieve	O
persistency	O
in	O
a	O
certain	O
data	B-General_Concept
structure	I-General_Concept
such	O
as	O
binary	B-Language
search	I-Language
trees	I-Language
.	O
</s>
<s>
It	O
is	O
nice	O
to	O
have	O
a	O
general	O
strategy	O
for	O
implementing	O
persistence	O
that	O
works	O
with	O
any	O
given	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
In	O
addition	O
to	O
that	O
there	O
is	O
an	O
array	B-Data_Structure
inedges( )	O
that	O
keeps	O
track	O
of	O
all	O
the	O
incoming	O
edges	O
to	O
.	O
</s>
<s>
We	O
need	O
to	O
loop	O
in	O
the	O
array	B-Data_Structure
inedges( )	O
in	O
order	O
to	O
let	O
each	O
vertex	O
in	O
the	O
array	B-Data_Structure
point	O
to	O
the	O
new	O
table	O
created	O
.	O
</s>
<s>
In	O
order	O
to	O
find	O
the	O
efficiency	O
of	O
the	O
scheme	B-Operating_System
proposed	O
above	O
,	O
we	O
use	O
an	O
argument	O
defined	O
as	O
a	O
credit	O
scheme	B-Operating_System
.	O
</s>
<s>
The	O
credit	O
scheme	B-Operating_System
should	O
always	O
satisfy	O
the	O
following	O
invariant	B-Application
:	O
Each	O
row	O
of	O
each	O
active	O
table	O
stores	O
one	O
credit	O
and	O
the	O
table	O
has	O
the	O
same	O
number	O
of	O
credits	O
as	O
the	O
number	O
of	O
rows	O
.	O
</s>
<s>
Let	O
us	O
confirm	O
that	O
the	O
invariant	B-Application
applies	O
to	O
all	O
the	O
three	O
operations	O
CREATE-NODE	O
,	O
CHANGE-EDGE	O
and	O
CHANGE-LABEL	O
.	O
</s>
<s>
Thus	O
the	O
invariant	B-Application
is	O
maintained	O
.	O
</s>
<s>
We	O
conclude	O
that	O
the	O
invariant	B-Application
is	O
maintained	O
.	O
</s>
<s>
We	O
conclude	O
that	O
There	O
exists	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
can	O
complete	O
any	O
sequence	O
of	O
CREATE-NODE	O
,	O
CHANGE-EDGE	O
and	O
CHANGE-LABEL	O
in	O
.	O
</s>
<s>
We	O
want	O
to	O
build	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
can	O
query	O
a	O
point	O
and	O
return	O
the	O
segment	O
above	O
(	O
if	O
any	O
)	O
.	O
</s>
<s>
We	O
will	O
start	O
by	O
solving	O
the	O
Next	O
Element	O
Search	O
using	O
the	O
naïve	O
method	O
then	O
we	O
will	O
show	O
how	O
to	O
solve	O
it	O
using	O
the	O
persistent	B-Application
data	I-Application
structure	I-Application
method	O
.	O
</s>
<s>
Thus	O
we	O
have	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
can	O
answer	O
any	O
query	O
.	O
</s>
<s>
In	O
this	O
data	B-General_Concept
structure	I-General_Concept
,	O
the	O
space	O
is	O
the	O
issue	O
since	O
if	O
we	O
assume	O
that	O
we	O
have	O
the	O
segments	O
structured	O
in	O
a	O
way	O
such	O
that	O
every	O
segment	O
starts	O
before	O
the	O
end	O
of	O
any	O
other	O
segment	O
,	O
then	O
the	O
space	O
required	O
for	O
the	O
structure	O
to	O
be	O
built	O
using	O
the	O
naïve	O
method	O
would	O
be	O
.	O
</s>
<s>
Let	O
us	O
see	O
how	O
we	O
can	O
build	O
another	O
persistent	B-Application
data	I-Application
structure	I-Application
with	O
the	O
same	O
query	O
time	O
but	O
with	O
a	O
better	O
space	O
.	O
</s>
<s>
We	O
can	O
notice	O
that	O
what	O
really	O
takes	O
time	O
in	O
the	O
data	B-General_Concept
structure	I-General_Concept
used	O
in	O
the	O
naïve	O
method	O
is	O
that	O
whenever	O
we	O
move	O
from	O
a	O
strip	O
to	O
the	O
next	O
,	O
we	O
need	O
to	O
take	O
a	O
snap	O
shot	O
of	O
whatever	O
data	B-General_Concept
structure	I-General_Concept
we	O
are	O
using	O
to	O
keep	O
things	O
in	O
sorted	O
order	O
.	O
</s>
<s>
Let	O
us	O
assume	O
that	O
we	O
have	O
a	O
tree	B-Application
rooted	O
at	O
.	O
</s>
<s>
When	O
we	O
insert	O
a	O
key	O
into	O
the	O
tree	B-Application
,	O
we	O
create	O
a	O
new	O
leaf	O
containing	O
.	O
</s>
<s>
Performing	O
rotations	O
to	O
rebalance	O
the	O
tree	B-Application
will	O
only	O
modify	O
the	O
nodes	O
of	O
the	O
path	O
from	O
to	O
.	O
</s>
<s>
Before	O
inserting	O
the	O
key	O
into	O
the	O
tree	B-Application
,	O
we	O
copy	O
all	O
the	O
nodes	O
on	O
the	O
path	O
from	O
to	O
.	O
</s>
<s>
Now	O
we	O
have	O
2	O
versions	O
of	O
the	O
tree	B-Application
,	O
the	O
original	O
one	O
which	O
does	O
n't	O
contain	O
and	O
the	O
new	O
tree	B-Application
that	O
contains	O
and	O
whose	O
root	O
is	O
a	O
copy	O
of	O
the	O
root	O
of	O
.	O
</s>
<s>
Since	O
copying	O
the	O
path	O
from	O
to	O
does	O
n't	O
increase	O
the	O
insertion	O
time	O
by	O
more	O
than	O
a	O
constant	O
factor	O
then	O
the	O
insertion	O
in	O
the	O
persistent	B-Application
data	I-Application
structure	I-Application
takes	O
time	O
.	O
</s>
<s>
This	O
will	O
provide	O
a	O
new	O
tree	B-Application
whose	O
root	O
is	O
a	O
copy	O
of	O
the	O
root	O
of	O
the	O
original	O
tree	B-Application
.	O
</s>
<s>
Then	O
we	O
perform	O
the	O
deletion	O
on	O
the	O
new	O
tree	B-Application
.	O
</s>
<s>
We	O
will	O
end	O
up	O
with	O
2	O
versions	O
of	O
the	O
tree	B-Application
.	O
</s>
<s>
Since	O
any	O
deletion	O
only	O
modifies	O
the	O
path	O
from	O
the	O
root	O
to	O
and	O
any	O
appropriate	O
deletion	O
algorithm	O
runs	O
in	O
,	O
thus	O
the	O
deletion	O
in	O
the	O
persistent	B-Application
data	I-Application
structure	I-Application
takes	O
.	O
</s>
<s>
Using	O
this	O
persistent	B-Application
data	I-Application
structure	I-Application
we	O
can	O
solve	O
the	O
next	O
element	O
search	O
problem	O
in	O
query	O
time	O
and	O
space	O
instead	O
of	O
.	O
</s>
<s>
Perhaps	O
the	O
simplest	O
persistent	B-Application
data	I-Application
structure	I-Application
is	O
the	O
singly	B-Data_Structure
linked	I-Data_Structure
list	I-Data_Structure
or	O
cons-based	O
list	O
,	O
a	O
simple	O
list	O
of	O
objects	O
formed	O
by	O
each	O
carrying	O
a	O
reference	O
to	O
the	O
next	O
in	O
the	O
list	O
.	O
</s>
<s>
So	O
long	O
as	O
the	O
contents	O
of	O
the	O
tail	O
are	O
immutable	B-Application
,	O
this	O
sharing	O
will	O
be	O
invisible	O
to	O
the	O
program	O
.	O
</s>
<s>
Many	O
common	O
reference-based	O
data	B-General_Concept
structures	I-General_Concept
,	O
such	O
as	O
red	O
–	O
black	O
trees	O
,	O
stacks	B-Application
,	O
and	O
treaps	B-Application
,	O
can	O
easily	O
be	O
adapted	O
to	O
create	O
a	O
persistent	O
version	O
.	O
</s>
<s>
Some	O
others	O
need	O
slightly	O
more	O
effort	O
,	O
for	O
example	O
:	O
queues	B-Application
,	O
dequeues	B-Application
,	O
and	O
extensions	O
including	O
min-deques	O
(	O
which	O
have	O
an	O
additional	O
O(1 )	O
operation	O
min	O
returning	O
the	O
minimal	O
element	O
)	O
and	O
random	O
access	O
deques	B-Application
(	O
which	O
have	O
an	O
additional	O
operation	O
of	O
random	O
access	O
with	O
sub-linear	O
,	O
most	O
often	O
logarithmic	O
,	O
complexity	O
)	O
.	O
</s>
<s>
There	O
also	O
exist	O
persistent	B-Application
data	I-Application
structures	I-Application
which	O
use	O
destructive	O
operations	O
,	O
making	O
them	O
impossible	O
to	O
implement	O
efficiently	O
in	O
purely	O
functional	B-Language
languages	I-Language
(	O
like	O
Haskell	B-Language
outside	O
specialized	O
monads	O
like	O
state	O
or	O
IO	O
)	O
,	O
but	O
possible	O
in	O
languages	O
like	O
C	O
or	O
Java	B-Language
.	O
</s>
<s>
These	O
types	B-General_Concept
of	I-General_Concept
data	I-General_Concept
structures	I-General_Concept
can	O
often	O
be	O
avoided	O
with	O
a	O
different	O
design	O
.	O
</s>
<s>
One	O
primary	O
advantage	O
to	O
using	O
purely	O
persistent	B-Application
data	I-Application
structures	I-Application
is	O
that	O
they	O
often	O
behave	O
better	O
in	O
multi-threaded	O
environments	O
.	O
</s>
<s>
Singly	O
linked	B-Data_Structure
lists	I-Data_Structure
are	O
the	O
bread-and-butter	O
data	B-General_Concept
structure	I-General_Concept
in	O
functional	B-Language
languages	I-Language
.	O
</s>
<s>
Some	O
ML-derived	O
languages	O
,	O
like	O
Haskell	B-Language
,	O
are	O
purely	O
functional	O
because	O
once	O
a	O
node	O
in	O
the	O
list	O
has	O
been	O
allocated	O
,	O
it	O
cannot	O
be	O
modified	O
,	O
only	O
copied	O
,	O
referenced	O
or	O
destroyed	O
by	O
the	O
garbage	B-General_Concept
collector	I-General_Concept
when	O
nothing	O
refers	O
to	O
it	O
.	O
</s>
<s>
(	O
Note	O
that	O
ML	B-Language
itself	O
is	O
not	O
purely	O
functional	O
,	O
but	O
supports	O
non-destructive	O
list	O
operations	O
subset	O
,	O
that	O
is	O
also	O
true	O
in	O
the	O
Lisp	B-Language
(	O
LISt	B-Language
Processing	I-Language
)	O
functional	B-Language
language	I-Language
dialects	O
like	O
Scheme	B-Operating_System
and	O
Racket	B-Operating_System
.	O
)	O
</s>
<s>
Consider	O
a	O
binary	B-Language
search	I-Language
tree	I-Language
,	O
where	O
every	O
node	O
in	O
the	O
tree	B-Application
has	O
the	O
recursive	O
invariant	B-Application
that	O
all	O
subnodes	O
contained	O
in	O
the	O
left	O
subtree	B-Application
have	O
a	O
value	O
that	O
is	O
less	O
than	O
or	O
equal	O
to	O
the	O
value	O
stored	O
in	O
the	O
node	O
,	O
and	O
subnodes	O
contained	O
in	O
the	O
right	O
subtree	B-Application
have	O
a	O
value	O
that	O
is	O
greater	O
than	O
the	O
value	O
stored	O
in	O
the	O
node	O
.	O
</s>
<s>
might	O
be	O
represented	O
by	O
the	O
following	O
binary	B-Language
search	I-Language
tree	I-Language
:	O
</s>
<s>
Notice	O
two	O
points	O
:	O
first	O
,	O
the	O
original	O
tree	B-Application
(	O
xs	O
)	O
persists	O
.	O
</s>
<s>
Second	O
,	O
many	O
common	O
nodes	O
are	O
shared	O
between	O
the	O
old	O
tree	B-Application
and	O
the	O
new	O
tree	B-Application
.	O
</s>
<s>
Such	O
persistence	O
and	O
sharing	O
is	O
difficult	O
to	O
manage	O
without	O
some	O
form	O
of	O
garbage	B-General_Concept
collection	I-General_Concept
(	O
GC	O
)	O
to	O
automatically	O
free	O
up	O
nodes	O
which	O
have	O
no	O
live	O
references	O
,	O
and	O
this	O
is	O
why	O
GC	O
is	O
a	O
feature	O
commonly	O
found	O
in	O
functional	B-Language
programming	I-Language
languages	I-Language
.	O
</s>
<s>
A	O
persistent	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
trie	I-Data_Structure
is	O
a	O
specialized	O
variant	O
of	O
a	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
trie	I-Data_Structure
that	O
will	O
preserve	O
previous	O
versions	O
of	O
itself	O
on	O
any	O
updates	O
.	O
</s>
<s>
It	O
is	O
often	O
used	O
to	O
implement	O
a	O
general	O
purpose	O
persistent	O
map	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
Hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
tries	I-Data_Structure
were	O
originally	O
described	O
in	O
a	O
2001	O
paper	O
by	O
Phil	O
Bagwell	O
entitled	O
"	O
Ideal	O
Hash	B-Error_Name
Trees	O
"	O
.	O
</s>
<s>
This	O
paper	O
presented	O
a	O
mutable	B-Application
Hash	B-Algorithm
table	I-Algorithm
where	O
"	O
Insert	O
,	O
search	O
and	O
delete	O
times	O
are	O
small	O
and	O
constant	O
,	O
independent	O
of	O
key	O
set	O
size	O
,	O
operations	O
are	O
O(1 )	O
.	O
</s>
<s>
This	O
data	B-General_Concept
structure	I-General_Concept
was	O
then	O
modified	O
by	O
Rich	O
Hickey	O
to	O
be	O
fully	O
persistent	O
for	O
use	O
in	O
the	O
Clojure	B-Language
programming	O
language	O
.	O
</s>
<s>
Conceptually	O
,	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
tries	I-Data_Structure
work	O
similar	O
to	O
any	O
generic	O
tree	B-Application
in	O
that	O
they	O
store	O
nodes	O
hierarchically	O
and	O
retrieve	O
them	O
by	O
following	O
a	O
path	O
down	O
to	O
a	O
particular	O
element	O
.	O
</s>
<s>
The	O
key	O
difference	O
is	O
that	O
Hash	B-Data_Structure
Array	I-Data_Structure
Mapped	I-Data_Structure
Tries	I-Data_Structure
first	O
use	O
a	O
hash	B-Error_Name
function	I-Error_Name
to	O
transform	O
their	O
lookup	B-Data_Structure
key	O
into	O
a	O
(	O
usually	O
32	O
or	O
64	O
bit	O
)	O
integer	O
.	O
</s>
<s>
The	O
path	O
down	O
the	O
tree	B-Application
is	O
then	O
determined	O
by	O
using	O
slices	O
of	O
the	O
binary	O
representation	O
of	O
that	O
integer	O
to	O
index	O
into	O
a	O
sparse	B-Algorithm
array	I-Algorithm
at	O
each	O
level	O
of	O
the	O
tree	B-Application
.	O
</s>
<s>
The	O
leaf	B-Application
nodes	I-Application
of	O
the	O
tree	B-Application
behave	O
similar	O
to	O
the	O
buckets	O
used	O
to	O
construct	O
hash	B-Algorithm
tables	I-Algorithm
and	O
may	O
or	O
may	O
not	O
contain	O
multiple	O
candidates	O
depending	O
on	O
hash	B-Algorithm
collisions	I-Algorithm
.	O
</s>
<s>
Most	O
implementations	O
of	O
persistent	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
tries	I-Data_Structure
use	O
a	O
branching	O
factor	O
of	O
32	O
in	O
their	O
implementation	O
.	O
</s>
<s>
This	O
means	O
that	O
in	O
practice	O
while	O
insertions	O
,	O
deletions	O
,	O
and	O
lookups	B-Data_Structure
into	O
a	O
persistent	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
trie	I-Data_Structure
have	O
a	O
computational	O
complexity	O
of	O
O(log n )	O
,	O
for	O
most	O
applications	O
they	O
are	O
effectively	O
constant	O
time	O
,	O
as	O
it	O
would	O
require	O
an	O
extremely	O
large	O
number	O
of	O
entries	O
to	O
make	O
any	O
operation	O
take	O
more	O
than	O
a	O
dozen	O
steps	O
.	O
</s>
<s>
Haskell	B-Language
is	O
a	O
pure	O
functional	B-Language
language	I-Language
and	O
therefore	O
does	O
not	O
allow	O
for	O
mutation	O
.	O
</s>
<s>
Therefore	O
,	O
all	O
data	B-General_Concept
structures	I-General_Concept
in	O
the	O
language	O
are	O
persistent	O
,	O
as	O
it	O
is	O
impossible	O
to	O
not	O
preserve	O
the	O
previous	O
state	O
of	O
a	O
data	B-General_Concept
structure	I-General_Concept
with	O
functional	O
semantics	O
.	O
</s>
<s>
This	O
is	O
because	O
any	O
change	O
to	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
would	O
render	O
previous	O
versions	O
of	O
a	O
data	B-General_Concept
structure	I-General_Concept
invalid	O
would	O
violate	O
referential	O
transparency	O
.	O
</s>
<s>
In	O
its	O
standard	O
library	O
Haskell	B-Language
has	O
efficient	O
persistent	O
implementations	O
for	O
linked	B-Data_Structure
lists	I-Data_Structure
,	O
Maps	O
(	O
implemented	O
as	O
size	O
balanced	O
trees	O
)	O
,	O
and	O
Sets	O
among	O
others	O
.	O
</s>
<s>
Like	O
many	O
programming	O
languages	O
in	O
the	O
Lisp	B-Language
family	O
,	O
Clojure	B-Language
contains	O
an	O
implementation	O
of	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
but	O
unlike	O
other	O
dialects	O
its	O
implementation	O
of	O
a	O
Linked	B-Data_Structure
List	I-Data_Structure
has	O
enforced	O
persistence	O
instead	O
of	O
being	O
persistent	O
by	O
convention	O
.	O
</s>
<s>
Clojure	B-Language
also	O
has	O
efficient	O
implementations	O
of	O
persistent	O
vectors	O
,	O
maps	O
,	O
and	O
sets	O
based	O
on	O
persistent	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
tries	I-Data_Structure
.	O
</s>
<s>
These	O
data	B-General_Concept
structures	I-General_Concept
implement	O
the	O
mandatory	O
read-only	O
parts	O
of	O
the	O
Java	B-Language
collections	I-Language
framework	I-Language
.	O
</s>
<s>
The	O
designers	O
of	O
the	O
Clojure	B-Language
language	O
advocate	O
the	O
use	O
of	O
persistent	B-Application
data	I-Application
structures	I-Application
over	O
mutable	B-Application
data	B-General_Concept
structures	I-General_Concept
because	O
they	O
have	O
value	B-Application
semantics	I-Application
which	O
gives	O
the	O
benefit	O
of	O
making	O
them	O
freely	O
shareable	O
between	O
threads	O
with	O
cheap	O
aliases	O
,	O
easy	O
to	O
fabricate	O
,	O
and	O
language	O
independent	O
.	O
</s>
<s>
These	O
data	B-General_Concept
structures	I-General_Concept
form	O
the	O
basis	O
of	O
Clojure	B-Language
's	O
support	O
for	O
parallel	B-Operating_System
computing	I-Operating_System
since	O
they	O
allow	O
for	O
easy	O
retries	O
of	O
operations	O
to	O
sidestep	O
data	O
races	O
and	O
atomic	O
compare	B-Operating_System
and	I-Operating_System
swap	I-Operating_System
semantics	O
.	O
</s>
<s>
The	O
Elm	B-Language
programming	I-Language
language	I-Language
is	O
purely	O
functional	O
like	O
Haskell	B-Language
,	O
which	O
makes	O
all	O
of	O
its	O
data	B-General_Concept
structures	I-General_Concept
persistent	O
by	O
necessity	O
.	O
</s>
<s>
It	O
contains	O
persistent	O
implementations	O
of	O
linked	B-Data_Structure
lists	I-Data_Structure
as	O
well	O
as	O
persistent	O
arrays	O
,	O
dictionaries	O
,	O
and	O
sets	O
.	O
</s>
<s>
Elm	B-Language
uses	O
a	O
custom	O
virtual	B-General_Concept
DOM	I-General_Concept
implementation	O
that	O
takes	O
advantage	O
of	O
the	O
persistent	O
nature	O
of	O
Elm	B-Language
data	O
.	O
</s>
<s>
As	O
of	O
2016	O
it	O
was	O
reported	O
by	O
the	O
developers	O
of	O
Elm	B-Language
that	O
this	O
virtual	B-General_Concept
DOM	I-General_Concept
allows	O
the	O
Elm	B-Language
language	O
to	O
render	O
HTML	O
faster	O
than	O
the	O
popular	O
JavaScript	B-Language
frameworks	O
React	B-Application
,	O
Ember	B-Language
,	O
and	O
Angular	B-Language
.	O
</s>
<s>
The	O
Java	B-Language
programming	I-Language
language	I-Language
is	O
not	O
particularly	O
functional	O
.	O
</s>
<s>
Despite	O
this	O
,	O
the	O
core	O
JDK	O
package	O
java.util.concurrent	O
includes	O
CopyOnWriteArrayList	O
and	O
CopyOnWriteArraySet	O
which	O
are	O
persistent	O
structures	O
,	O
implemented	O
using	O
copy-on-write	B-Language
techniques	O
.	O
</s>
<s>
The	O
usual	O
concurrent	B-Operating_System
map	O
implementation	O
in	O
Java	B-Language
,	O
ConcurrentHashMap	O
,	O
is	O
not	O
persistent	O
,	O
however	O
.	O
</s>
<s>
The	O
popular	O
JavaScript	B-Language
frontend	O
framework	O
React	B-Application
is	O
frequently	O
used	O
along	O
with	O
a	O
state	O
management	O
system	O
that	O
implements	O
the	O
Flux	O
architecture	O
,	O
a	O
popular	O
implementation	O
of	O
which	O
is	O
the	O
JavaScript	B-Language
library	O
Redux	B-Language
.	O
</s>
<s>
The	O
Redux	B-Language
library	O
is	O
inspired	O
by	O
the	O
state	O
management	O
pattern	O
used	O
in	O
the	O
Elm	B-Language
programming	I-Language
language	I-Language
,	O
meaning	O
that	O
it	O
mandates	O
that	O
users	O
treat	O
all	O
data	O
as	O
persistent	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
the	O
Redux	B-Language
project	O
recommends	O
that	O
in	O
certain	O
cases	O
users	O
make	O
use	O
of	O
libraries	O
for	O
enforced	O
and	O
efficient	O
persistent	B-Application
data	I-Application
structures	I-Application
.	O
</s>
<s>
This	O
reportedly	O
allows	O
for	O
greater	O
performance	O
than	O
when	O
comparing	O
or	O
making	O
copies	O
of	O
regular	O
JavaScript	B-Language
objects	O
.	O
</s>
<s>
One	O
such	O
library	O
of	O
persistent	B-Application
data	I-Application
structures	I-Application
Immutable.js	O
is	O
based	O
on	O
the	O
data	B-General_Concept
structures	I-General_Concept
made	O
available	O
and	O
popularized	O
by	O
Clojure	B-Language
and	O
Scala	O
.	O
</s>
<s>
It	O
is	O
mentioned	O
by	O
the	O
documentation	O
of	O
Redux	B-Language
as	O
being	O
one	O
of	O
the	O
possible	O
libraries	O
that	O
can	O
provide	O
enforced	O
immutability	B-Application
.	O
</s>
<s>
Mori.js	O
brings	O
data	B-General_Concept
structures	I-General_Concept
similar	O
to	O
those	O
in	O
Clojure	B-Language
to	O
JavaScript	B-Language
.	O
</s>
<s>
Immer.js	O
brings	O
an	O
interesting	O
approach	O
where	O
one	O
"	O
creates	O
the	O
next	O
immutable	B-Application
state	O
by	O
mutating	O
the	O
current	O
one	O
"	O
.	O
</s>
<s>
Immer.js	O
uses	O
native	O
JavaScript	B-Language
objects	O
and	O
not	O
efficient	O
persistent	B-Application
data	I-Application
structures	I-Application
and	O
it	O
might	O
cause	O
performance	O
issues	O
when	O
data	O
size	O
is	O
big	O
.	O
</s>
<s>
Prolog	O
terms	O
are	O
naturally	O
immutable	B-Application
and	O
therefore	O
data	B-General_Concept
structures	I-General_Concept
are	O
typically	O
persistent	B-Application
data	I-Application
structures	I-Application
.	O
</s>
<s>
Their	O
performance	O
depends	O
on	O
sharing	O
and	O
garbage	B-General_Concept
collection	I-General_Concept
offered	O
by	O
the	O
Prolog	O
system	O
.	O
</s>
<s>
The	O
Scala	O
programming	O
language	O
promotes	O
the	O
use	O
of	O
persistent	B-Application
data	I-Application
structures	I-Application
for	O
implementing	O
programs	O
using	O
"	O
Object-Functional	O
Style	O
"	O
.	O
</s>
<s>
Scala	O
contains	O
implementations	O
of	O
many	O
Persistent	B-Application
data	I-Application
structures	I-Application
including	O
Linked	B-Data_Structure
Lists	I-Data_Structure
,	O
Red	O
–	O
black	O
trees	O
,	O
as	O
well	O
as	O
persistent	O
hash	B-Data_Structure
array	I-Data_Structure
mapped	I-Data_Structure
tries	I-Data_Structure
as	O
introduced	O
in	O
Clojure	B-Language
.	O
</s>
<s>
Because	O
persistent	B-Application
data	I-Application
structures	I-Application
are	O
often	O
implemented	O
in	O
such	O
a	O
way	O
that	O
successive	O
versions	O
of	O
a	O
data	B-General_Concept
structure	I-General_Concept
share	O
underlying	O
memory	O
ergonomic	O
use	O
of	O
such	O
data	B-General_Concept
structures	I-General_Concept
generally	O
requires	O
some	O
form	O
of	O
automatic	B-General_Concept
garbage	I-General_Concept
collection	I-General_Concept
system	O
such	O
as	O
reference	B-General_Concept
counting	I-General_Concept
or	O
mark	O
and	O
sweep	O
.	O
</s>
<s>
In	O
some	O
platforms	O
where	O
persistent	B-Application
data	I-Application
structures	I-Application
are	O
used	O
it	O
is	O
an	O
option	O
to	O
not	O
use	O
garbage	B-General_Concept
collection	I-General_Concept
which	O
,	O
while	O
doing	O
so	O
can	O
lead	O
to	O
memory	B-Error_Name
leaks	I-Error_Name
,	O
can	O
in	O
some	O
cases	O
have	O
a	O
positive	O
impact	O
on	O
the	O
overall	O
performance	O
of	O
an	O
application	O
.	O
</s>
