An rstack is a "Last In, First Out" (LIFO) structure imagined as being organized from top (last in) to bottom (first in), supporting efficient insertion into the top, removal from the top, and peeking/accessing the top element. All functions supported by rstacks are side-effect free.
Other handy functions supported by rstacks
as.data.frame (the latter of which requires that
all elements can be appended to become rows of a data frame in a reasonable manner). Operations
are amortized O(1).
The rstack class also supports
rev - this operation is O(N), and results in a copy. This
means previous versions will retain their O(1) amortized nature (if we assume the cost of the
reverse is charged to the newly created stack), at the cost of memory usage. However, this also means
that if stacks are used in a non-persistent way, e.g.
s <- rev(s), then the garbage collector
is free to clean up old versions of the data.
an empty rstack.
Okasaki, Chris. Purely Functional Data Structures. Cambridge University Press, 1999.
insert_top for insertion,
without_top for removal,
peek_top for peeking.
1 2 3 4 5 6 7 8 9 10 11