123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(** An interface for stacks that follows [Core]'s conventions, as opposed to OCaml's
standard [Stack] module. *)open!ImportmoduletypeS=sigtype'at[@@deriving_inlinesexp,sexp_grammar]includeSexplib0.Sexpable.S1withtype'at:='atvalt_sexp_grammar:'aSexplib0.Sexp_grammar.t->'atSexplib0.Sexp_grammar.t[@@@end]includeInvariant.S1withtype'at:='at(** [fold], [iter], [find], and [find_map] visit the elements in order from the top of
the stack to the bottom. [to_list] and [to_array] return the elements in order from
the top of the stack to the bottom.
Iteration functions ([iter], [fold], etc.) have unspecified behavior (although they
should still be memory-safe) when the stack is mutated while they are running (e.g.
by having the passed-in function call [push] or [pop] on the stack).
*)includeContainer.S1withtype'at:='at(** [of_list l] returns a stack whose top is the first element of [l] and bottom is the
last element of [l]. *)valof_list:'alist->'at(** [create ()] returns an empty stack. *)valcreate:unit->_t(** [singleton a] creates a new stack containing only [a]. *)valsingleton:'a->'at(** [push t a] adds [a] to the top of stack [t]. *)valpush:'at->'a->unit(** [pop t] removes and returns the top element of [t] as [Some a], or returns [None] if
[t] is empty. *)valpop:'at->'aoptionvalpop_exn:'at->'a(** [top t] returns [Some a], where [a] is the top of [t], unless [is_empty t], in which
case [top] returns [None]. *)valtop:'at->'aoptionvaltop_exn:'at->'a(** [clear t] discards all elements from [t]. *)valclear:_t->unit(** [copy t] returns a copy of [t]. *)valcopy:'at->'at(** [until_empty t f] repeatedly pops an element [a] off of [t] and runs [f a], 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 next. *)valuntil_empty:'at->(('a->unit)[@local])->unit(** [filter_map t ~f] creates a new stack with only the elements for which [f] returns
[Some] *)valfilter_map:'at->f:(('a->'boption)[@local])->'bt(** [filter t ~f] creates a new stack with only the elements that satisfy [f]. *)valfilter:'at->f:(('a->bool)[@local])->'at(** [filter_inplace t ~f] removes all elements of [t] that don't satisfy [f]. *)valfilter_inplace:'at->f:(('a->bool)[@local])->unitend(** A stack implemented with an array.
The implementation will grow the array as necessary, and will never automatically
shrink the array. One can use [set_capacity] to explicitly resize the array. *)moduletypeStack=sigmoduletypeS=SincludeS(** @open *)(** [capacity t] returns the length of the array backing [t]. *)valcapacity:_t->int(** [set_capacity t capacity] sets the length of the array backing [t] to [max capacity
(length t)]. To shrink as much as possible, do [set_capacity t 0]. *)valset_capacity:_t->int->unitend