A fastqueue
is backed by a list, which is used in a circular manner. The
backing list will grow or shrink as the queue changes in size.
fastqueue(init = 20, missing_default = NULL)
Initial size of the list that backs the queue. This is also used as the minimum size of the list; it will not shrink any smaller.
The value to return when remove()
or peek()
are
called when the stack is empty. Default is NULL
.
fastqueue
objects have the following methods:
add(x)
Add an object to the queue.
madd(..., .list = NULL)
Add objects to the queue. .list
can be a list of objects to add.
remove(missing = missing_default)
Remove and return the next object in the queue, but do not remove it from
the queue. If the queue is empty, this will return missing
, which
defaults to the value of missing_default
that queue()
was created
with (typically, NULL
).
mremove(n, missing = missing_default)
Remove and return the next n
objects on the queue, in a list. The first
element of the list is the oldest object in the queue (in other words,
the next item that would be returned by remove()
). If n
is greater
than the number of objects in the queue, any requested items beyond
those in the queue will be replaced with missing
(typically, NULL
).
peek(missing = missing_default)
Return the next object in the queue but do not remove it from the queue.
If the queue is empty, this will return missing
.
reset()
Reset the queue, clearing all items.
size()
Returns the number of items in the queue.
as_list()
Return a list containing the objects in the queue, where the first
element in the list is oldest object in the queue (in other words, it is
the next item that would be returned by remove()
), and the last element
in the list is the most recently added object.