Library
Module
Module type
Parameter
Class
Class type
Last-In First-Out (LIFO) stack.
The interface provides a subset of the OCaml Stdlib.Stack
module. add_seq
is not provided at all. Compositional versions of iter
, fold
, pop
, and top
are not provided.
The implementation is essentially a Treiber stack with randomized exponential backoff and support for constant time length
.
val create : unit -> 'a t
create ()
returns a new empty stack.
module Tx : sig ... end
Transactions on stacks.
module Xt : sig ... end
Explicit transaction log passing on stacks.
val is_empty : 'a t -> bool
is_empty s
determines whether the stack s
is empty.
val length : 'a t -> int
length s
returns the length of the stack s
.
val clear : 'a t -> unit
clear s
removes all elements from the stack s
.
to_seq s
returns a domain safe sequence for iterating through the elements of the stack top to bottom.
The sequence is based on a constant time, O(1)
, snapshot of the stack and modifications of the stack have no effect on the sequence.
val push : 'a -> 'a t -> unit
push x s
adds the element x
to the top of the stack s
.
val pop_opt : 'a t -> 'a option
pop_opt s
removes and returns the topmost element of the stack s
, or None
if the stack is empty.
val top_opt : 'a t -> 'a option
top_opt s
returns the topmost element in stack s
, or None
if the stack is empty.
val pop : 'a t -> 'a
pop s
removes and returns the topmost element in stack s
, or raises Empty
if the stack is empty.
val top : 'a t -> 'a
top s
returns the topmost element in stack s
, or raises Empty
if the stack is empty.
val iter : ('a -> unit) -> 'a t -> unit
iter f s
is equivalent to Seq.iter f (to_seq s)
.
val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
fold f s
is equivalent to Seq.fold_left f a (to_seq s)
.