module Stack:Core_stack is a replacement for OCaml's standard Stack module that follows Core idioms and adds some functions.sig
..end
Differences from the standard module:
pop
and top
return an option
rather than raise Empty
.
iter
takes a labeled argument.
push
takes the stack argument first.
length
is O(1)
exception Empty
type 'a
t
include Container.S1
to_list
and to_array
returns the elements in order from the top of
the stack to the bottom.val of_list : 'a list -> 'a t
of_list l
returns a stack whose top is the first element of l
and
* bottom is the last element of l
.val invariant : 'a t -> unit
val create : unit -> 'a t
create ()
returns an empty stack.val push : 'a t -> 'a -> unit
push t x
adds x
to the top of stack t
.val pop : 'a t -> 'a option
pop t
returns None
if t
is empty, otherwise it returns Some x
where
x
is the top of t
and removes x
from the top of t
.val pop_exn : 'a t -> 'a
pop_exn t
removes and returns the top element of t
, raising Empty
if
t
is empty.val top : 'a t -> 'a option
top t
returns None
if t
is empty, otherwise it returns Some x
where
x
is the top of t
.val top_exn : 'a t -> 'a
top_exn t
returns the top element of t
, raising Empty
if t
is empty.val clear : 'a t -> unit
clear t
discards all elements from t
.val copy : 'a t -> 'a t
copy t
returns a copy of t
.val until_empty : 'a t -> ('a -> unit) -> unit
until_empty t f
repeatedly pops an element v
off of t
and runs f v
until t
becomes empty. It is fine if f
adds more elements to t
, in
which case the most-recently-added element will be processed first.val t_of_sexp : (Sexplib.Sexp.t -> 'a) -> Sexplib.Sexp.t -> 'a t
val sexp_of_t : ('a -> Sexplib.Sexp.t) -> 'a t -> Sexplib.Sexp.t
val bin_t : 'a Bin_prot.Type_class.t -> 'a t Bin_prot.Type_class.t
val bin_read_t : 'a Bin_prot.Unsafe_read_c.reader -> 'a t Bin_prot.Read_ml.reader
val bin_read_t_ : 'a Bin_prot.Unsafe_read_c.reader ->
'a t Bin_prot.Unsafe_read_c.reader
val bin_read_t__ : 'a Bin_prot.Unsafe_read_c.reader ->
(int -> 'a t) Bin_prot.Unsafe_read_c.reader
val bin_reader_t : 'a Bin_prot.Type_class.reader -> 'a t Bin_prot.Type_class.reader
val bin_size_t : 'a Bin_prot.Size.sizer -> 'a t Bin_prot.Size.sizer
val bin_write_t : 'a Bin_prot.Unsafe_write_c.writer -> 'a t Bin_prot.Write_ml.writer
val bin_write_t_ : 'a Bin_prot.Unsafe_write_c.writer ->
'a t Bin_prot.Unsafe_write_c.writer
val bin_writer_t : 'a Bin_prot.Type_class.writer -> 'a t Bin_prot.Type_class.writer