man-pages/man3/Stack.3o.html
2021-03-31 01:06:50 +01:00

356 lines
3.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Stack</TITLE>
</HEAD><BODY>
<H1>Stack</H1>
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Stack - Last-in first-out stacks.
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Stack
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Stack</B>
<BR>&nbsp;:&nbsp;
<B>sig end</B>
<P>
<P>
Last-in first-out stacks.
<P>
This module implements stacks (LIFOs), with in-place modification.
<P>
<P>
<P>
<P>
<P>
<I>type </I>
<B>'a</B>
<I>t </I>
<P>
<P>
The type of stacks containing elements of type
<B>'a</B>
.
<P>
<P>
<P>
<I>exception Empty </I>
<P>
<P>
Raised when
<B>Stack.pop</B>
or
<B>Stack.top</B>
is applied to an empty stack.
<P>
<P>
<P>
<I>val create </I>
:
<B>unit -&gt; 'a t</B>
<P>
Return a new stack, initially empty.
<P>
<P>
<P>
<I>val push </I>
:
<B>'a -&gt; 'a t -&gt; unit</B>
<P>
<P>
<B>push x s</B>
adds the element
<B>x</B>
at the top of stack
<B>s</B>
.
<P>
<P>
<P>
<I>val pop </I>
:
<B>'a t -&gt; 'a</B>
<P>
<P>
<B>pop s</B>
removes and returns the topmost element in stack
<B>s</B>
,
or raises
<B>Stack.Empty</B>
if the stack is empty.
<P>
<P>
<P>
<I>val pop_opt </I>
:
<B>'a t -&gt; 'a option</B>
<P>
<P>
<B>pop_opt s</B>
removes and returns the topmost element in stack
<B>s</B>
,
or returns
<B>None</B>
if the stack is empty.
<P>
<P>
<B>Since</B>
4.08
<P>
<P>
<P>
<I>val top </I>
:
<B>'a t -&gt; 'a</B>
<P>
<P>
<B>top s</B>
returns the topmost element in stack
<B>s</B>
,
or raises
<B>Stack.Empty</B>
if the stack is empty.
<P>
<P>
<P>
<I>val top_opt </I>
:
<B>'a t -&gt; 'a option</B>
<P>
<P>
<B>top_opt s</B>
returns the topmost element in stack
<B>s</B>
,
or
<B>None</B>
if the stack is empty.
<P>
<P>
<B>Since</B>
4.08
<P>
<P>
<P>
<I>val clear </I>
:
<B>'a t -&gt; unit</B>
<P>
Discard all elements from a stack.
<P>
<P>
<P>
<I>val copy </I>
:
<B>'a t -&gt; 'a t</B>
<P>
Return a copy of the given stack.
<P>
<P>
<P>
<I>val is_empty </I>
:
<B>'a t -&gt; bool</B>
<P>
Return
<B>true</B>
if the given stack is empty,
<B>false</B>
otherwise.
<P>
<P>
<P>
<I>val length </I>
:
<B>'a t -&gt; int</B>
<P>
Return the number of elements in a stack. Time complexity <A HREF="/cgi-bin/man/man2html?1+O">O</A>(1)
<P>
<P>
<P>
<I>val iter </I>
:
<B>('a -&gt; unit) -&gt; 'a t -&gt; unit</B>
<P>
<P>
<B>iter f s</B>
applies
<B>f</B>
in turn to all elements of
<B>s</B>
,
from the element at the top of the stack to the element at the
bottom of the stack. The stack itself is unchanged.
<P>
<P>
<P>
<I>val fold </I>
:
<B>('b -&gt; 'a -&gt; 'b) -&gt; 'b -&gt; 'a t -&gt; 'b</B>
<P>
<P>
<B>fold f accu s</B>
is
<B>(f (... (f (f accu x1) x2) ...) xn)</B>
where
<B>x1</B>
is the top of the stack,
<B>x2</B>
the second element,
and
<B>xn</B>
the bottom element. The stack is unchanged.
<P>
<P>
<B>Since</B>
4.03
<P>
<P>
<P>
<P>
<A NAME="lbAE">&nbsp;</A>
<H3>Iterators</H3>
<P>
<P>
<P>
<I>val to_seq </I>
:
<B>'a t -&gt; 'a Seq.t</B>
<P>
Iterate on the stack, top to bottom.
It is safe to modify the stack during iteration.
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<I>val add_seq </I>
:
<B>'a t -&gt; 'a Seq.t -&gt; unit</B>
<P>
Add the elements from the iterator on the top of the stack.
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<I>val of_seq </I>
:
<B>'a Seq.t -&gt; 'a t</B>
<P>
Create a stack from the iterator
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">Module</A><DD>
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
<DL>
<DT id="4"><A HREF="#lbAE">Iterators</A><DD>
</DL>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:57 GMT, March 31, 2021
</BODY>
</HTML>