Handbook
Glossary
persistent-vector
Persistent vectors
Next:
>persistent-vector ( seq -- pvec )
Vocabulary
persistent
.
vectors
Class description
The class of persistent vectors.
Definition
USING:
math
persistent.vectors.private
;
IN:
persistent.vectors
TUPLE:
persistent-vector
{
count
fixnum
initial:
0
}
{
root
node
initial:
T{
node
{
level 1
}
}
}
{
tail
node
initial:
T{
node
}
}
;
Methods
USING:
persistent.vectors
prettyprint.custom
;
M:
persistent-vector
>pprint-sequence
;
USING:
kernel
persistent.vectors
sequences
;
M:
persistent-vector
equal?
over
persistent-vector?
[
sequence=
]
[
2drop
f
]
if
;
USING:
accessors
persistent.vectors
sequences
;
M:
persistent-vector
length
count>>
;
USING:
kernel
persistent.sequences
persistent.vectors
sequences
;
M:
persistent-vector
like
drop
PV{
}
[
swap
ppush
]
reduce
;
USING:
accessors
kernel
math
persistent.sequences
persistent.vectors
persistent.vectors.private
;
M:
persistent-vector
new-nth
2dup
count>>
=
[
nip
ppush
]
[
clone
2dup
tail-offset
>=
[
[
node-mask
]
dip
[
node-set-nth
]
change-tail
]
[
[
(new-nth)
]
change-root
]
if
]
if
;
USING:
accessors
kernel
math
persistent.vectors
persistent.vectors.private
sequences.private
;
M:
persistent-vector
nth-unsafe
2dup
tail-offset
>=
[
tail>>
]
[
root>>
body-nth
]
if
node-nth
;
USING:
accessors
combinators
kernel
math
persistent.sequences
persistent.vectors
persistent.vectors.private
sequences
;
M:
persistent-vector
ppop
dup
count>>
{
{
0
[
empty-error
]
}
{
1
[
drop
PV{
}
]
}
[
[
clone
dup
tail>>
children>>
length
1
>
[
ppop-tail
]
[
ppop-new-tail
]
if
]
dip
1
-
>>count
]
}
case
;
USING:
persistent.vectors
prettyprint.custom
;
M:
persistent-vector
pprint*
pprint-object
;
USING:
kernel
persistent.vectors
prettyprint.custom
;
M:
persistent-vector
pprint-delims
drop
\
PV{
\
}
;
USING:
accessors
kernel
math
persistent.sequences
persistent.vectors
persistent.vectors.private
;
M:
persistent-vector
ppush
clone
dup
tail>>
full?
[
ppush-new-tail
]
[
ppush-tail
]
if
[
1
+
]
change-count
;