mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-17 08:06:43 -05:00
13 lines
No EOL
3.3 KiB
HTML
13 lines
No EOL
3.3 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Set (ocaml.Stdlib.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> » <a href="../index.html">Stdlib</a> » Set</nav><header class="odoc-preamble"><h1>Module <code><span>Stdlib.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 -> Stdlib.compare y0 y1
|
||
| c -> c
|
||
end
|
||
|
||
module PairsSet = Set.Make(IntPairs)
|
||
|
||
let m = PairsSet.(empty |> add (2,3) |> add (5,7) |> 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></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> |