crew_class_queue {crew} | R Documentation |
R6
queue class
Description
R6
class for a queue.
Details
See the Details section of crew_queue()
.
The R6
crew
queue class is not portable (for efficiency),
so other packages should not inherit from it.
The reason for non-portability is efficiency: elements can be
directly accessed without self$
or private$
, and they can be
directly modified with <<-
.
This is especially important for push()
because
envir$vector[slice] <- x
copies the entire vector in memory,
which has O(n^2) complexity and is extremely slow for large vectors.
Active bindings
data
See
crew_queue()
.head
Non-negative integer pointing to the location of the next element to pop.
tail
Non-negative integer pointing to the tail of the queue.
step
See
crew_queue()
.
Methods
Public methods
Method new()
Create a queue object.
Usage
crew_class_queue$new(data = NULL, step = NULL)
Arguments
data
See
crew_queue()
.step
See
crew_queue()
.
Returns
A queue object.
Method validate()
Validate the queue.
Usage
crew_class_queue$validate()
Returns
NULL
(invisibly). Called for its side effects.
Method empty()
Check if the queue is empty.
Usage
crew_class_queue$empty()
Returns
TRUE
if the queue is empty, FALSE
otherwise.
Method nonempty()
Check if the queue is empty.
Usage
crew_class_queue$nonempty()
Returns
TRUE
if the queue is nonempty, FALSE
otherwise.
Method list()
List available data.
Usage
crew_class_queue$list()
Returns
Character vector of available data.
Method reset()
Reset the queue.
Usage
crew_class_queue$reset()
Returns
NULL
(invisibly). Called for its side effects.
Method clean()
Remove popped elements from the data in the queue.
Usage
crew_class_queue$clean()
Returns
NULL
(invisibly).
Method set()
Set the data in the queue.
Usage
crew_class_queue$set(data = character(0L))
Arguments
data
Character vector of data to set.
Returns
NULL
(invisibly). Called for its side effects.
Method extend()
Extend the queue data by step
elements.
Usage
crew_class_queue$extend(n)
Arguments
n
Positive integer, number of elements to extend the queue data.
Returns
NULL
(invisibly).
Method push()
Append new elements to the queue.
Usage
crew_class_queue$push(x)
Arguments
x
Character vector of new data to append.
Details
push()
is the reason the queue class is not portable.
According to R6 documentation,
members of non-portable classes
can be accessed without self$
or private$
,
and assignment can be done with <<-
.
In the case of push()
, this prevents each assignment from
deep-copying the entire contents of the vector.
Returns
NULL
(invisibly).
Method pop()
Pop one or more elements off the queue.
Usage
crew_class_queue$pop(n = 1L)
Arguments
n
Positive integer, maximum number of elements to pop. Fewer than
n
are popped if fewer thann
are available.
Returns
Character vector of elements popped off the queue.
NULL
if there are no more elements available to pop.
Method collect()
Remove and return all available elements off the queue.
Usage
crew_class_queue$collect()
Returns
Character vector, elements collected from the queue.
NULL
if there are no more elements available to collect.
See Also
Other queue:
crew_queue()
Examples
crew_queue()