ocaml-containers/2.4/containers/CCMixset/index.html
2018-12-23 21:02:45 -06:00

14 lines
No EOL
3.9 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>CCMixset (containers.CCMixset)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> <a href="../index.html">containers</a> &#x00BB; CCMixset</nav><h1>Module <code>CCMixset</code></h1><h2 id="set-of-heterogeneous-values"><a href="#set-of-heterogeneous-values" class="anchor"></a>Set of Heterogeneous Values</h2><pre><code class="ml">let k1 : int key = newkey () in
let k2 : int key = newkey () in
let k3 : string key = newkey () in
let set =
empty
|&gt; set ~key:k1 1
|&gt; set ~key:k2 2
|&gt; set ~key:k3 &quot;3&quot;
in
assert (get ~key:k1 set = Some 1);
assert (get ~key:k2 set = Some 2);
assert (get ~key:k3 set = Some &quot;3&quot;);
()</code></pre><dl><dt>since</dt><dd>0.11</dd></dl></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type </span>t</code></dt><dd><p>A set of values of heterogeneous types</p></dd></dl><dl><dt class="spec type" id="type-key"><a href="#type-key" class="anchor"></a><code><span class="keyword">type </span>'a key</code></dt><dd><p>A unique &quot;key&quot; to access a value of type <code>'a</code> in a <code>set</code></p></dd></dl><dl><dt class="spec value" id="val-newkey"><a href="#val-newkey" class="anchor"></a><code><span class="keyword">val </span>newkey : unit <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-key">key</a></code></dt><dd><p><code>newkey ()</code> creates a new unique key that can be used to access a <code>'a</code> value in a set. Each key created with <code>newkey</code> is distinct from any other key, even if they have the same type.</p><p>Not thread-safe.</p></dd></dl><dl><dt class="spec value" id="val-empty"><a href="#val-empty" class="anchor"></a><code><span class="keyword">val </span>empty : <a href="index.html#type-t">t</a></code></dt><dd><p>Empty set.</p></dd></dl><dl><dt class="spec value" id="val-set"><a href="#val-set" class="anchor"></a><code><span class="keyword">val </span>set : key:<span class="type-var">'a</span> <a href="index.html#type-key">key</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>set ~key v set</code> maps <code>key</code> to <code>v</code> in <code>set</code>. It means that for every <code>set</code>, <code>get ~key (set ~key v set) = Some v</code>.</p></dd></dl><dl><dt class="spec value" id="val-get"><a href="#val-get" class="anchor"></a><code><span class="keyword">val </span>get : key:<span class="type-var">'a</span> <a href="index.html#type-key">key</a> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> option</code></dt><dd><p><code>get ~key set</code> obtains the value for <code>key</code> in <code>set</code>, if any.</p></dd></dl><dl><dt class="spec value" id="val-get_exn"><a href="#val-get_exn" class="anchor"></a><code><span class="keyword">val </span>get_exn : key:<span class="type-var">'a</span> <a href="index.html#type-key">key</a> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p>Same as <a href="index.html#val-get"><code>get</code></a>, but can fail.</p><dl><dt>raises Not_found</dt><dd><p>if the key is not present.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-cardinal"><a href="#val-cardinal" class="anchor"></a><code><span class="keyword">val </span>cardinal : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dd><p>Number of mappings.</p></dd></dl></div></body></html>