faststack: Create a stack

View source: R/faststack.R

faststackR Documentation

Create a stack

Description

A faststack is backed by a list. The backing list will grow or shrink as the stack changes in size.

Usage

faststack(init = 20, missing_default = NULL)

Arguments

init

Initial size of the list that backs the stack. This is also used as the minimum size of the list; it will not shrink any smaller.

missing_default

The value to return when pop() or peek() are called when the stack is empty. Default is NULL.

Details

faststack objects have the following methods:

push(x)

Push an object onto the stack.

mpush(..., .list = NULL)

Push objects onto the stack. .list can be a list of objects to add.

pop(missing = missing_default)

Remove and return the top object on the stack. If the stack is empty, it will return missing, which defaults to the value of missing_default that stack() was created with (typically, NULL).

mpop(n, missing = missing_default)

Remove and return the top n objects on the stack, in a list. The first element of the list is the top object in the stack. If n is greater than the number of objects in the stack, any requested items beyond those in the stack will be replaced with missing (typically, NULL).

peek(missing = missing_default)

Return the top object on the stack, but do not remove it from the stack. If the stack is empty, this will return missing.

reset()

Reset the stack, clearing all items.

size()

Returns the number of items in the stack.

as_list()

Return a list containing the objects in the stack, where the first element in the list is the object at the bottom of the stack, and the last element in the list is the object at the top of the stack.


fastmap documentation built on June 22, 2024, 10:59 a.m.