Title: | Don't Get Stuck with Stacks in R |
---|---|
Description: | Functions to create and manipulate FIFO (First In First Out), LIFO (Last In First Out), and NINO (Not In or Never Out) stacks in R. |
Authors: | Paul Poncet [aut, cre] |
Maintainer: | Paul Poncet <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.5 |
Built: | 2024-10-27 05:50:03 UTC |
Source: | https://github.com/paulponcet/flifo |
flifo provides functions to create and manipulate FIFO (First In First Out), LIFO (Last In First Out), and NINO (Not In or Never Out) stacks in R, most notably:
This method tests if a stack x
is empty.
## S3 method for class 'stack' is.empty(x)
## S3 method for class 'stack' is.empty(x)
x |
A stack. |
A logical, TRUE
if x
is empty.
The generic function is.empty
in package bazar.
The fifo
, lifo
, and nino
functions
create 'First In First Out', 'Last In First Out', and
'Not In or Never Out' stacks, respectively.
is.stack(x) is.fifo(x) is.lifo(x) is.nino(x) ## S3 method for class 'stack' as.list(x, ...) fifo(max_length = Inf, max_size = Inf) lifo(max_length = Inf, max_size = Inf) nino(max_length = Inf, max_size = Inf)
is.stack(x) is.fifo(x) is.lifo(x) is.nino(x) ## S3 method for class 'stack' as.list(x, ...) fifo(max_length = Inf, max_size = Inf) lifo(max_length = Inf, max_size = Inf) nino(max_length = Inf, max_size = Inf)
x |
An object to be tested or coerced. |
... |
Additional arguments. |
max_length |
numeric. The maximum (infinite by default) number of objects the stack can contain. |
max_size |
numeric. The maximum (infinite by default) size of the stack, in octets. |
is.xxx
functions return a logical.
fifo
, lifo
, and nino
return
an empty FIFO, LIFO, or NINO stack.
The function max_length
returns the maximum number
of objects a stack can contains; this number can be changed
with max_length<-
.
max_length(.stack) max_length(x) <- value
max_length(.stack) max_length(x) <- value
.stack , x
|
A stack. |
value |
numeric. The new maximum length of the stack. |
max_length
returns a (possibly infinite)
nonnegative numeric.
The pop
function retrieves the first reachable
object from .stack
.
pop(.stack)
pop(.stack)
.stack |
A stack. |
The pop
function is not pure. Side effect is that
.stack
is modified in the calling environment.
The object retrieved.
If .stack
is empty, an error is thrown.
push
.
(s <- lifo(max_length = 3)) # empty LIFO (push(s, 0.3)) # (push(s, data.frame(x=1:2, y=2:3))) obj <- pop(s) # get the last element inserted
(s <- lifo(max_length = 3)) # empty LIFO (push(s, 0.3)) # (push(s, data.frame(x=1:2, y=2:3))) obj <- pop(s) # get the last element inserted
The function print.stack
prints the class of the stack x
(FIFO, LIFO, or NINO) and displays
its next reachable object.
## S3 method for class 'stack' print(x, ...)
## S3 method for class 'stack' print(x, ...)
x |
A stack. |
... |
Additional arguments. |
The stack x
is returned invisibly.
The push
function inserts an
object into .stack
.
push(.stack, x)
push(.stack, x)
.stack |
A stack. |
x |
An object to insert in |
The push
function is not pure. Side effects (made on purpose) are:
.stack
is modified in the calling environment;
x
is removed (deleted) if it exists in the calling environment.
NULL
is returned invisibly.
pop
.
(s <- lifo(max_length = 3)) # empty LIFO (push(s, 0.3)) # (push(s, data.frame(x=1:2, y=2:3))) obj <- pop(s) # get the last element inserted
(s <- lifo(max_length = 3)) # empty LIFO (push(s, 0.3)) # (push(s, data.frame(x=1:2, y=2:3))) obj <- pop(s) # get the last element inserted
The function size
returns the size of a stack, in bytes.
The function max_size
returns the maximum number
of objects a stack can contains; this number can be changed
with max_size<-
.
size(.stack) max_size(.stack) max_size(x) <- value
size(.stack) max_size(.stack) max_size(x) <- value
.stack |
A stack. |
x |
A stack. |
value |
numeric. The new maximum size of the stack. |
size
always returns a nonnegative numeric.
max_size
returns a (possibly infinite) nonnegative numeric.