R/stack.R

#' Stack
#' @name stack
#' @export
#' @include container.R
NULL

stack <- Container("stack",
  new = function() {
    pointer <- stack_create()
    local({
      finalize <- function() stack_release(pointer)
      empty <- function() stack_empty(pointer)
      size <- function() stack_size(pointer)
      push <- function(x) stack_push(pointer, x)
      pop <- function() stack_pop(pointer)
      top <- function() stack_top(pointer)
      container(environment(), "stack")
    })
  })
renkun-ken/container documentation built on May 27, 2019, 4:55 a.m.