crew_class_queue | R Documentation |
R6
queue classR6
class for a queue.
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.
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()
.
new()
Create a queue object.
crew_class_queue$new(data = NULL, step = NULL)
data
See crew_queue()
.
step
See crew_queue()
.
A queue object.
validate()
Validate the queue.
crew_class_queue$validate()
NULL
(invisibly). Called for its side effects.
empty()
Check if the queue is empty.
crew_class_queue$empty()
TRUE
if the queue is empty, FALSE
otherwise.
nonempty()
Check if the queue is empty.
crew_class_queue$nonempty()
TRUE
if the queue is nonempty, FALSE
otherwise.
list()
List available data.
crew_class_queue$list()
Character vector of available data.
reset()
Reset the queue.
crew_class_queue$reset()
NULL
(invisibly). Called for its side effects.
clean()
Remove popped elements from the data in the queue.
crew_class_queue$clean()
NULL
(invisibly).
set()
Set the data in the queue.
crew_class_queue$set(data = character(0L))
data
Character vector of data to set.
NULL
(invisibly). Called for its side effects.
extend()
Extend the queue data by step
elements.
crew_class_queue$extend(n)
n
Positive integer, number of elements to extend the queue data.
NULL
(invisibly).
push()
Append new elements to the queue.
crew_class_queue$push(x)
x
Character vector of new data to append.
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.
NULL
(invisibly).
pop()
Pop one or more elements off the queue.
crew_class_queue$pop(n = 1L)
n
Positive integer, maximum number of elements to pop.
Fewer than n
are popped if fewer than n
are available.
Character vector of elements popped off the queue.
NULL
if there are no more elements available to pop.
collect()
Remove and return all available elements off the queue.
crew_class_queue$collect()
Character vector, elements collected from the queue.
NULL
if there are no more elements available to collect.
Other queue:
crew_queue()
crew_queue()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.