ocaml-containers/2.8/containers/CCMixtbl/index.html
2019-12-14 17:27:18 -06:00

22 lines
No EOL
9.7 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>CCMixtbl (containers.CCMixtbl)</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; CCMixtbl</nav><h1>Module <code>CCMixtbl</code></h1><h2 id="hash-table-with-heterogeneous-keys"><a href="#hash-table-with-heterogeneous-keys" class="anchor"></a>Hash Table with Heterogeneous Keys</h2><p>From https://github.com/mjambon/mixtbl (thanks to him). Example:</p><pre><code class="ml">let inj_int = CCMixtbl.create_inj () ;;
let tbl = CCMixtbl.create 10 ;;
OUnit.assert_equal None (CCMixtbl.get ~inj:inj_int tbl &quot;a&quot;);;
CCMixtbl.set inj_int tbl &quot;a&quot; 1;;
OUnit.assert_equal (Some 1) (CCMixtbl.get ~inj:inj_int tbl &quot;a&quot;);;
let inj_string = CCMixtbl.create_inj () ;;
CCMixtbl.set inj_string tbl &quot;b&quot; &quot;Hello&quot;;
OUnit.assert_equal (Some &quot;Hello&quot;) (CCMixtbl.get inj_string tbl &quot;b&quot;);;
OUnit.assert_equal None (CCMixtbl.get inj_string tbl &quot;a&quot;);;
OUnit.assert_equal (Some 1) (CCMixtbl.get inj_int tbl &quot;a&quot;);;
CCMixtbl.set inj_string tbl &quot;a&quot; &quot;Bye&quot;;;
OUnit.assert_equal None (CCMixtbl.get inj_int tbl &quot;a&quot;);;
OUnit.assert_equal (Some &quot;Bye&quot;) (CCMixtbl.get inj_string tbl &quot;a&quot;);;</code></pre><dl><dt>since</dt><dd>0.6</dd></dl><nav class="toc"><ul><li><a href="#iterators">Iterators</a></li></ul></nav></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> 'a t</code></dt><dd><p>A hash table containing values of different types. The type parameter <code>'a</code> represents the type of the keys.</p></dd></dl><dl><dt class="spec type" id="type-injection"><a href="#type-injection" class="anchor"></a><code><span class="keyword">type</span> 'b injection</code></dt><dd><p>An accessor for values of type 'b in any table. Values put in the table using a key can only be retrieved using this very same key.</p></dd></dl><dl><dt class="spec value" id="val-create"><a href="#val-create" class="anchor"></a><code><span class="keyword">val</span> create : int <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>create n</code> creates a hash table of initial size <code>n</code>.</p></dd></dl><dl><dt class="spec value" id="val-create_inj"><a href="#val-create_inj" class="anchor"></a><code><span class="keyword">val</span> create_inj : unit <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-injection">injection</a></code></dt><dd><p>Return a value that works for a given type of values. This function is normally called once for each type of value. Several keys may be created for the same type, but a value set with a given setter can only be retrieved with the matching getter. The same key can be reused across multiple tables (although not in a thread-safe way).</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 : inj:<span class="type-var">'b</span> <a href="index.html#type-injection">injection</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> option</code></dt><dd><p>Get the value corresponding to this key, if it exists and belongs to the same key.</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 : inj:<span class="type-var">'b</span> <a href="index.html#type-injection">injection</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> unit</code></dt><dd><p>Bind the key to the value, using <code>inj</code>.</p></dd></dl><dl><dt class="spec value" id="val-find"><a href="#val-find" class="anchor"></a><code><span class="keyword">val</span> find : inj:<span class="type-var">'b</span> <a href="index.html#type-injection">injection</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span></code></dt><dd><p>Find the value for the given key, which must be of the right type.</p><dl><dt>raises Not_found</dt><dd><p>if either the key is not found, or if its value doesn't belong to the right type.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-length"><a href="#val-length" class="anchor"></a><code><span class="keyword">val</span> length : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dd><p>Number of bindings.</p></dd></dl><dl><dt class="spec value" id="val-clear"><a href="#val-clear" class="anchor"></a><code><span class="keyword">val</span> clear : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Clear content of the hashtable.</p></dd></dl><dl><dt class="spec value" id="val-remove"><a href="#val-remove" class="anchor"></a><code><span class="keyword">val</span> remove : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> unit</code></dt><dd><p>Remove the binding for this key.</p></dd></dl><dl><dt class="spec value" id="val-copy"><a href="#val-copy" class="anchor"></a><code><span class="keyword">val</span> copy : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Copy of the table.</p></dd></dl><dl><dt class="spec value" id="val-mem"><a href="#val-mem" class="anchor"></a><code><span class="keyword">val</span> mem : inj:<span class="type-var">_</span> <a href="index.html#type-injection">injection</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> bool</code></dt><dd><p>Is the given key in the table, with the right type?</p></dd></dl><dl><dt class="spec value" id="val-iter_keys"><a href="#val-iter_keys" class="anchor"></a><code><span class="keyword">val</span> iter_keys : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> unit</code></dt><dd><p>Iterate on the keys of this table.</p></dd></dl><dl><dt class="spec value" id="val-fold_keys"><a href="#val-fold_keys" class="anchor"></a><code><span class="keyword">val</span> fold_keys : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> (<span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'b</span></code></dt><dd><p>Fold over the keys.</p></dd></dl><section><header><h3 id="iterators"><a href="#iterators" class="anchor"></a>Iterators</h3></header><dl><dt class="spec type" id="type-sequence"><a href="#type-sequence" class="anchor"></a><code><span class="keyword">type</span> 'a sequence</code><code> = (<span class="type-var">'a</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> unit</code></dt></dl><dl><dt class="spec value" id="val-keys_seq"><a href="#val-keys_seq" class="anchor"></a><code><span class="keyword">val</span> keys_seq : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-sequence">sequence</a></code></dt><dd><p>All the keys.</p></dd></dl><dl><dt class="spec value" id="val-bindings_of"><a href="#val-bindings_of" class="anchor"></a><code><span class="keyword">val</span> bindings_of : inj:<span class="type-var">'b</span> <a href="index.html#type-injection">injection</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-sequence">sequence</a></code></dt><dd><p>All the bindings that come from the corresponding injection.</p></dd></dl><dl><dt class="spec type" id="type-value"><a href="#type-value" class="anchor"></a><code><span class="keyword">type</span> value</code><code> = </code><table class="variant"><tr id="type-value.Value" class="anchored"><td class="def constructor"><a href="#type-value.Value" class="anchor"></a><code>| </code><code><span class="constructor">Value</span> : (<span class="type-var">'b</span> <a href="index.html#type-injection">injection</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> option) <span>&#45;&gt;</span> <a href="index.html#type-value">value</a></code></td></tr></table></dt></dl><dl><dt class="spec value" id="val-bindings"><a href="#val-bindings" class="anchor"></a><code><span class="keyword">val</span> bindings : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <a href="index.html#type-value">value</a>) <a href="index.html#type-sequence">sequence</a></code></dt><dd><p>Iterate on all bindings.</p></dd></dl></section></div></body></html>