436 lines
4.7 KiB
HTML
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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Queue - First-in first-out queues.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Queue
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Queue</B>
|
|
|
|
<BR> :
|
|
<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 -> 'a t</B>
|
|
|
|
<P>
|
|
Return a new queue, initially empty.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val add </I>
|
|
|
|
:
|
|
<B>'a -> 'a t -> 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 -> 'a t -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>push</B>
|
|
|
|
is a synonym for
|
|
<B>add</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val take </I>
|
|
|
|
:
|
|
<B>'a t -> '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 -> '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 -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>pop</B>
|
|
|
|
is a synonym for
|
|
<B>take</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val peek </I>
|
|
|
|
:
|
|
<B>'a t -> '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 -> '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 -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>top</B>
|
|
|
|
is a synonym for
|
|
<B>peek</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val clear </I>
|
|
|
|
:
|
|
<B>'a t -> unit</B>
|
|
|
|
<P>
|
|
Discard all elements from a queue.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val copy </I>
|
|
|
|
:
|
|
<B>'a t -> 'a t</B>
|
|
|
|
<P>
|
|
Return a copy of the given queue.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val is_empty </I>
|
|
|
|
:
|
|
<B>'a t -> 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 -> int</B>
|
|
|
|
<P>
|
|
Return the number of elements in a queue.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val iter </I>
|
|
|
|
:
|
|
<B>('a -> unit) -> 'a t -> 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 -> 'a -> 'b) -> 'b -> 'a t -> '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 -> 'a t -> 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 -> add x q2) q1; clear q1</B>
|
|
|
|
, but runs
|
|
in constant time.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Iterators</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val to_seq </I>
|
|
|
|
:
|
|
<B>'a t -> '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 -> 'a Seq.t -> 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 -> 'a t</B>
|
|
|
|
<P>
|
|
Create a queue from the generator
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.07
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </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>
|