Description Usage Details Value References See Also Examples
Creates a new, empty, rdeque ready for use.
1 | rdeque()
|
An rdeque provided both "Last In, First Out" (LIFO) and "First In, First Out" (FIFO) access;
envisaged as queue, elements may be added or removed from the front or the back with insert_front
,
insert_back
, without_front
, and without_back
. The front and back
elements may be retrieved with peek_front
and peek_back
.
Internally, rdeques are stored as a pair of rstacks; they provide O(1)-amortized insertion and removal,
so long as they are not used persistently (that is, the variable storing the deque is always replaced
by the modified version, e.g. s <- without_front(s)
). When used persistently (e.g. s2 <- without_front(s)
, which results
in two deques being accessible), this cannot be gauranteed. When an O(1) worst-cast, fully
persistent FIFO queue is needed, the rpqueue from this package provides these semantics. However,
there is a constant-time overhead for rpqueues, such that rdeques are often more efficient (and flexible)
in practice, even in when used persistently.
Other useful functions
include as.list
and 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).
a new empty rdeque.
Okasaki, Chris. Purely Functional Data Structures. Cambridge University Press, 1999.
rstack
for a fast LIFO-only structure.
1 2 3 4 5 6 7 8 9 10 11 12 13 | d <- rdeque()
d <- insert_front(d, "a")
d <- insert_front(d, "b")
d <- insert_back(d, "c")
d <- insert_back(d, "d")
print(d)
d2 <- without_back(d)
print(d2)
print(d)
b <- peek_front(d)
print(b)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.