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

436 lines
4.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Queue</TITLE>
</HEAD><BODY>
<H1>Queue</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>
Queue - First-in first-out queues.
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Queue
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Queue</B>
<BR>&nbsp;:&nbsp;
<B>sig end</B>
<P>
<P>
First-in first-out queues.
<P>
This module implements queues (FIFOs), with in-place modification.
<P>
Warning This module is not thread-safe: each
<B>Queue.t</B>
value
must be protected from concurrent access (e.g. with a
<B>Mutex.t</B>
).
Failure to do so can lead to a crash.
<P>
<P>
<P>
<P>
<P>
<I>type </I>
<B>'a</B>
<I>t </I>
<P>
<P>
The type of queues containing elements of type
<B>'a</B>
.
<P>
<P>
<P>
<I>exception Empty </I>
<P>
<P>
Raised when
<B>Queue.take</B>
or
<B>Queue.peek</B>
is applied to an empty queue.
<P>
<P>
<P>
<I>val create </I>
:
<B>unit -&gt; 'a t</B>
<P>
Return a new queue, initially empty.
<P>
<P>
<P>
<I>val add </I>
:
<B>'a -&gt; 'a t -&gt; unit</B>
<P>
<P>
<B>add x q</B>
adds the element
<B>x</B>
at the end of the queue
<B>q</B>
.
<P>
<P>
<P>
<I>val push </I>
:
<B>'a -&gt; 'a t -&gt; unit</B>
<P>
<P>
<B>push</B>
is a synonym for
<B>add</B>
.
<P>
<P>
<P>
<I>val take </I>
:
<B>'a t -&gt; 'a</B>
<P>
<P>
<B>take q</B>
removes and returns the first element in queue
<B>q</B>
,
or raises
<B>Queue.Empty</B>
if the queue is empty.
<P>
<P>
<P>
<I>val take_opt </I>
:
<B>'a t -&gt; 'a option</B>
<P>
<P>
<B>take_opt q</B>
removes and returns the first element in queue
<B>q</B>
,
or returns
<B>None</B>
if the queue is empty.
<P>
<P>
<B>Since</B>
4.08
<P>
<P>
<P>
<I>val pop </I>
:
<B>'a t -&gt; 'a</B>
<P>
<P>
<B>pop</B>
is a synonym for
<B>take</B>
.
<P>
<P>
<P>
<I>val peek </I>
:
<B>'a t -&gt; 'a</B>
<P>
<P>
<B>peek q</B>
returns the first element in queue
<B>q</B>
, without removing
it from the queue, or raises
<B>Queue.Empty</B>
if the queue is empty.
<P>
<P>
<P>
<I>val peek_opt </I>
:
<B>'a t -&gt; 'a option</B>
<P>
<P>
<B>peek_opt q</B>
returns the first element in queue
<B>q</B>
, without removing
it from the queue, or returns
<B>None</B>
if the queue 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</B>
is a synonym for
<B>peek</B>
.
<P>
<P>
<P>
<I>val clear </I>
:
<B>'a t -&gt; unit</B>
<P>
Discard all elements from a queue.
<P>
<P>
<P>
<I>val copy </I>
:
<B>'a t -&gt; 'a t</B>
<P>
Return a copy of the given queue.
<P>
<P>
<P>
<I>val is_empty </I>
:
<B>'a t -&gt; bool</B>
<P>
Return
<B>true</B>
if the given queue 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 queue.
<P>
<P>
<P>
<I>val iter </I>
:
<B>('a -&gt; unit) -&gt; 'a t -&gt; unit</B>
<P>
<P>
<B>iter f q</B>
applies
<B>f</B>
in turn to all elements of
<B>q</B>
,
from the least recently entered to the most recently entered.
The queue 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 q</B>
is equivalent to
<B>List.fold_left f accu l</B>
,
where
<B>l</B>
is the list of
<B>q</B>
's elements. The queue remains
unchanged.
<P>
<P>
<P>
<I>val transfer </I>
:
<B>'a t -&gt; 'a t -&gt; unit</B>
<P>
<P>
<B>transfer q1 q2</B>
adds all of
<B>q1</B>
's elements at the end of
the queue
<B>q2</B>
, then clears
<B>q1</B>
. It is equivalent to the
sequence
<B>iter (fun x -&gt; add x q2) q1; clear q1</B>
, but runs
in constant time.
<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 queue, in front-to-back order.
The behavior is not defined if the queue is modified
during the 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 generator to the end of the queue
<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 queue from the generator
<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:53 GMT, March 31, 2021
</BODY>
</HTML>