moonpool/dev/ocaml/Stdlib/MoreLabels/Set/index.html
2023-08-28 17:11:38 +00:00

15 lines
No EOL
3.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Set (ocaml.Stdlib.MoreLabels.Set)</title><link rel="stylesheet" href="../../../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../../index.html">ocaml</a> &#x00BB; <a href="../../index.html">Stdlib</a> &#x00BB; <a href="../index.html">MoreLabels</a> &#x00BB; Set</nav><header class="odoc-preamble"><h1>Module <code><span>MoreLabels.Set</span></code></h1><p>Sets over ordered types.</p><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><p>The <a href="Make/index.html"><code>Make</code></a> functor constructs implementations for any type, given a <code>compare</code> function. For instance:</p><pre class="language-ocaml"><code>module IntPairs =
struct
type t = int * int
let compare (x0,y0) (x1,y1) =
match Stdlib.compare x0 x1 with
0 -&gt; Stdlib.compare y0 y1
| c -&gt; c
end
module PairsSet = Set.Make(IntPairs)
let m = PairsSet.(empty |&gt; add (2,3) |&gt; add (5,7) |&gt; add (11,13))</code></pre><p>This creates a new module <code>PairsSet</code>, with a new type <code>PairsSet.t</code> of sets of <code>int * int</code>.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-OrderedType"><a href="#module-type-OrderedType" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-OrderedType/index.html">OrderedType</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Input signature of the functor <a href="Make/index.html"><code>Make</code></a>.</p></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-S"><a href="#module-type-S" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-S/index.html">S</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Output signature of the functor <a href="Make/index.html"><code>Make</code></a>.</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Make"><a href="#module-Make" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Make/index.html">Make</a></span><span>
(<a href="Make/argument-1-Ord/index.html">Ord</a> : <a href="module-type-OrderedType/index.html">OrderedType</a>) :
<a href="module-type-S/index.html">S</a> <span class="keyword">with</span> <span><span class="keyword">type</span> <a href="module-type-S/index.html#type-elt">elt</a> = <a href="Make/argument-1-Ord/index.html#type-t">Ord.t</a></span> <span class="keyword">and</span> <span><span class="keyword">type</span> <a href="module-type-S/index.html#type-t">t</a> = <a href="../../Set/Make/index.html#type-t">Set.Make(Ord).t</a></span></span></code></div><div class="spec-doc"><p>Functor building an implementation of the set structure given a totally ordered type.</p></div></div></div></body></html>