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

140 lines
2.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Set</TITLE>
</HEAD><BODY>
<H1>Set</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>
Set - Sets over ordered types.
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Set
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Set</B>
<BR>&nbsp;:&nbsp;
<B>sig end</B>
<P>
<P>
Sets over ordered types.
<P>
This module implements the set data structure, given a total ordering
function over the set elements. All operations over sets
are purely applicative (no side-effects).
The implementation uses balanced binary trees, and is therefore
reasonably efficient: insertion and membership take time
logarithmic in the size of the set, for instance.
<P>
The
<B>Set.Make</B>
functor constructs implementations for any type, given a
<B>compare</B>
function.
For instance:
<B>module IntPairs =</B>
<B>struct</B>
<B>type t = int * int</B>
<B>let compare (x0,y0) (x1,y1) =</B>
<B>match Stdlib.compare x0 x1 with</B>
<B>0 -&gt; Stdlib.compare y0 y1</B>
<B>| c -&gt; c</B>
<B>end</B>
<B>module PairsSet = Set.Make(IntPairs)</B>
<B>let m = PairsSet.(empty |&gt; add (2,3) |&gt; add (5,7) |&gt; add (11,13))</B>
<B><P>
</B>
This creates a new module
<B>PairsSet</B>
, with a new type
<B>PairsSet.t</B>
of sets of
<B>int * int</B>
.
<P>
<P>
<P>
<P>
<P>
<I>module type OrderedType = </I>
<B>sig end</B>
<P>
<P>
Input signature of the functor
<B>Set.Make</B>
.
<P>
<P>
<I>module type S = </I>
<B>sig end</B>
<P>
<P>
Output signature of the functor
<B>Set.Make</B>
.
<P>
<P>
<I>module Make : </I>
<B>functor (Ord : OrderedType) -&gt; sig end</B>
<P>
<P>
Functor building an implementation of the set structure
given a totally ordered type.
<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>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:56 GMT, March 31, 2021
</BODY>
</HTML>