R/as.list.rpqueue.R

Defines functions as.list.rpqueue

Documented in as.list.rpqueue

#' @export
#' @title Convert an rpqueue to a list
#' 
#' @description Converts an rpqueue to a list, where the front of the queue becomes
#' the first element of the list, the second-from-front the second, and so on. 
#' 
#' @details Runs in \eqn{O(N)} time in the size of the rpqueue, but the generated list is pre-allocated for efficiency.
#' @param x rpqueue to convert.
#' @param ... additional arguments passed to as.list after initial conversion to list.
#' @return a list containing the elements of the rpqueue in front-to-back order.
#' @seealso \code{\link{as.data.frame.rpqueue}} and the generic \code{\link{as.list}}.
#' @examples
#' q <- rpqueue()
#' q <- insert_back(q, "a")
#' q <- insert_back(q, "b")
#' 
#' qlist <- as.list(q)
#' print(qlist)
#' @export
as.list.rpqueue <- function(x, ...) {
  return(as.list(c(as.list(x$l), rev(as.list(x$r))), ...))
}

Try the rstackdeque package in your browser

Any scripts or data that you put into this service are public.

rstackdeque documentation built on May 2, 2019, 4:15 a.m.