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.
See also
Other queue:
crew_queue()
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
Method new()
Create a queue object.
Usage
crew_class_queue$new(data = NULL, step = NULL)
Arguments
data
See
crew_queue()
.step
See
crew_queue()
.
Method list()
List available data.
Method push()
Append new elements to the queue.
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.
Method pop()
Pop one or more elements off the queue.
Examples
crew_queue()
#> <crew_class_queue>
#> Public:
#> clean: function ()
#> collect: function ()
#> data: active binding
#> empty: function ()
#> extend: function (n)
#> head: active binding
#> initialize: function (data = NULL, step = NULL)
#> list: function ()
#> nonempty: function ()
#> pop: function (n = 1L)
#> private: environment
#> push: function (x)
#> reset: function ()
#> self: crew_class_queue, R6
#> set: function (data = character(0L))
#> step: active binding
#> tail: active binding
#> validate: function ()
#> Private:
#> .data:
#> .head: 1
#> .step: 1000
#> .tail: 0