mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-17 08:06:43 -05:00
15 lines
No EOL
3.7 KiB
HTML
15 lines
No EOL
3.7 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Map (ocaml.Stdlib.MoreLabels.Map)</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> » <a href="../index.html">MoreLabels</a> » Map</nav><header class="odoc-preamble"><h1>Module <code><span>MoreLabels.Map</span></code></h1><p>Association tables over ordered types.</p><p>This module implements applicative association tables, also known as finite maps or dictionaries, given a total ordering function over the keys. All operations over maps are purely applicative (no side-effects). The implementation uses balanced binary trees, and therefore searching and insertion take time logarithmic in the size of the map.</p><p>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 PairsMap = Map.Make(IntPairs)
|
||
|
||
let m = PairsMap.(empty |> add (0,1) "hello" |> add (1,0) "world")</code></pre><p>This creates a new module <code>PairsMap</code>, with a new type <code>'a PairsMap.t</code> of maps from <code>int * int</code> to <code>'a</code>. In this example, <code>m</code> contains <code>string</code> values so its type is <code>string PairsMap.t</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-key">key</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> <span>'a <a href="module-type-S/index.html#type-t">t</a></span> = <span><span class="type-var">'a</span> <a href="../../Map/Make/index.html#type-t">Map.Make(Ord).t</a></span></span></span></code></div><div class="spec-doc"><p>Functor building an implementation of the map structure given a totally ordered type.</p></div></div></div></body></html> |