mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
44 lines
No EOL
64 KiB
HTML
44 lines
No EOL
64 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Hashtbl (containers.Containers.Hashtbl)</title><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.0"/><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">containers</a> » <a href="../index.html">Containers</a> » Hashtbl</nav><header class="odoc-preamble"><h1>Module <code><span>Containers.Hashtbl</span></code></h1><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.14</li></ul></header><div class="odoc-content"><div class="odoc-include"><details open="open"><summary class="spec include"><code><span><span class="keyword">include</span> <span class="keyword">module</span> <span class="keyword">type</span> <span class="keyword">of</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html">Stdlib.Hashtbl</a>
|
||
<span class="keyword">with</span> <span><span class="keyword">type</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-statistics">statistics</a> = <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-statistics">Stdlib.Hashtbl.statistics</a></span>
|
||
<span class="keyword">and</span> <span><span class="keyword">module</span> <a href="../../../ocaml/Stdlib/Hashtbl/Make/index.html">Make</a> = <a href="../../../ocaml/Stdlib/Hashtbl/Make/index.html">Stdlib.Hashtbl.Make</a></span>
|
||
<span class="keyword">and</span> <span><span class="keyword">type</span> <span>('a, 'b) <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">t</a></span> = <span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></span></code></summary><h2 id="generic-interface"><a href="#generic-interface" class="anchor"></a>Generic interface</h2><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> <span>('a, 'b) t</span></span><span> = <span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></code></div><div class="spec-doc"><p>The type of hash tables from type <code>'a</code> to type <code>'b</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-create"><a href="#val-create" class="anchor"></a><code><span><span class="keyword">val</span> create : <span>?random:bool <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>Hashtbl.create n</code> creates a new, empty hash table, with initial size <code>n</code>. For best results, <code>n</code> should be on the order of the expected number of elements that will be in the table. The table grows as needed, so <code>n</code> is just an initial guess.</p><p>The optional <code>~</code><code>random</code> parameter (a boolean) controls whether the internal organization of the hash table is randomized at each execution of <code>Hashtbl.create</code> or deterministic over all executions.</p><p>A hash table that is created with <code>~</code><code>random</code> set to <code>false</code> uses a fixed hash function (<a href="#val-hash"><code>hash</code></a>) to distribute keys among buckets. As a consequence, collisions between keys happen deterministically. In Web-facing applications or other security-sensitive applications, the deterministic collision patterns can be exploited by a malicious user to create a denial-of-service attack: the attacker sends input crafted to create many collisions in the table, slowing the application down.</p><p>A hash table that is created with <code>~</code><code>random</code> set to <code>true</code> uses the seeded hash function <a href="#val-seeded_hash"><code>seeded_hash</code></a> with a seed that is randomly chosen at hash table creation time. In effect, the hash function used is randomly selected among <code>2^{30}</code> different hash functions. All these hash functions have different collision patterns, rendering ineffective the denial-of-service attack described above. However, because of randomization, enumerating all elements of the hash table using <a href="#val-fold"><code>fold</code></a> or <a href="#val-iter"><code>iter</code></a> is no longer deterministic: elements are enumerated in different orders at different runs of the program.</p><p>If no <code>~</code><code>random</code> parameter is given, hash tables are created in non-random mode by default. This default can be changed either programmatically by calling <a href="#val-randomize"><code>randomize</code></a> or by setting the <code>R</code> flag in the <code>OCAMLRUNPARAM</code> environment variable.</p><ul class="at-tags"><li class="before"><span class="at-tag">before</span> <span class="value">4.00.0</span> <p>the <code>~</code><code>random</code> parameter was not present and all hash tables were created in non-randomized mode.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-clear"><a href="#val-clear" class="anchor"></a><code><span><span class="keyword">val</span> clear : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Empty a hash table. Use <code>reset</code> instead of <code>clear</code> to shrink the size of the bucket table to its initial size.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-reset"><a href="#val-reset" class="anchor"></a><code><span><span class="keyword">val</span> reset : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Empty a hash table and shrink the size of the bucket table to its initial size.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-copy"><a href="#val-copy" class="anchor"></a><code><span><span class="keyword">val</span> copy : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Return a copy of the given hashtable.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add"><a href="#val-add" class="anchor"></a><code><span><span class="keyword">val</span> add : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>Hashtbl.add tbl key data</code> adds a binding of <code>key</code> to <code>data</code> in table <code>tbl</code>. Previous bindings for <code>key</code> are not removed, but simply hidden. That is, after performing <a href="#val-remove"><code>remove</code></a><code> tbl key</code>, the previous binding for <code>key</code>, if any, is restored. (Same behavior as with association lists.)</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-find"><a href="#val-find" class="anchor"></a><code><span><span class="keyword">val</span> find : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span class="type-var">'b</span></span></code></div><div class="spec-doc"><p><code>Hashtbl.find tbl x</code> returns the current binding of <code>x</code> in <code>tbl</code>, or raises <code>Not_found</code> if no such binding exists.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-find_opt"><a href="#val-find_opt" class="anchor"></a><code><span><span class="keyword">val</span> find_opt : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> option</span></span></code></div><div class="spec-doc"><p><code>Hashtbl.find_opt tbl x</code> returns the current binding of <code>x</code> in <code>tbl</code>, or <code>None</code> if no such binding exists.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-find_all"><a href="#val-find_all" class="anchor"></a><code><span><span class="keyword">val</span> find_all : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> list</span></span></code></div><div class="spec-doc"><p><code>Hashtbl.find_all tbl x</code> returns the list of all data associated with <code>x</code> in <code>tbl</code>. The current binding is returned first, then the previous bindings, in reverse order of introduction in the table.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mem"><a href="#val-mem" class="anchor"></a><code><span><span class="keyword">val</span> mem : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>Hashtbl.mem tbl x</code> checks if <code>x</code> is bound in <code>tbl</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-remove"><a href="#val-remove" class="anchor"></a><code><span><span class="keyword">val</span> remove : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>Hashtbl.remove tbl x</code> removes the current binding of <code>x</code> in <code>tbl</code>, restoring the previous binding if it exists. It does nothing if <code>x</code> is not bound in <code>tbl</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-replace"><a href="#val-replace" class="anchor"></a><code><span><span class="keyword">val</span> replace : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>Hashtbl.replace tbl key data</code> replaces the current binding of <code>key</code> in <code>tbl</code> by a binding of <code>key</code> to <code>data</code>. If <code>key</code> is unbound in <code>tbl</code>, a binding of <code>key</code> to <code>data</code> is added to <code>tbl</code>. This is functionally equivalent to <a href="#val-remove"><code>remove</code></a><code> tbl key</code> followed by <a href="#val-add"><code>add</code></a><code> tbl key data</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-iter"><a href="#val-iter" class="anchor"></a><code><span><span class="keyword">val</span> iter : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> unit)</span> <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>Hashtbl.iter f tbl</code> applies <code>f</code> to all bindings in table <code>tbl</code>. <code>f</code> receives the key as first argument, and the associated value as second argument. Each binding is presented exactly once to <code>f</code>.</p><p>The order in which the bindings are passed to <code>f</code> is unspecified. However, if the table contains several bindings for the same key, they are passed to <code>f</code> in reverse order of introduction, that is, the most recent binding is passed first.</p><p>If the hash table was created in non-randomized mode, the order in which the bindings are enumerated is reproducible between successive runs of the program, and even between minor versions of OCaml. For randomized hash tables, the order of enumeration is entirely random.</p><p>The behavior is not specified if the hash table is modified by <code>f</code> during the iteration.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-filter_map_inplace"><a href="#val-filter_map_inplace" class="anchor"></a><code><span><span class="keyword">val</span> filter_map_inplace : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> option</span>)</span> <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>Hashtbl.filter_map_inplace f tbl</code> applies <code>f</code> to all bindings in table <code>tbl</code> and update each binding depending on the result of <code>f</code>. If <code>f</code> returns <code>None</code>, the binding is discarded. If it returns <code>Some new_val</code>, the binding is update to associate the key to <code>new_val</code>.</p><p>Other comments for <a href="#val-iter"><code>iter</code></a> apply as well.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.03.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fold"><a href="#val-fold" class="anchor"></a><code><span><span class="keyword">val</span> fold : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span><span class="type-var">'c</span> <span class="arrow">-></span></span> <span class="type-var">'c</span>)</span> <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'c</span> <span class="arrow">-></span></span> <span class="type-var">'c</span></span></code></div><div class="spec-doc"><p><code>Hashtbl.fold f tbl init</code> computes <code>(f kN dN ... (f k1 d1 init)...)</code>, where <code>k1 ... kN</code> are the keys of all bindings in <code>tbl</code>, and <code>d1 ... dN</code> are the associated values. Each binding is presented exactly once to <code>f</code>.</p><p>The order in which the bindings are passed to <code>f</code> is unspecified. However, if the table contains several bindings for the same key, they are passed to <code>f</code> in reverse order of introduction, that is, the most recent binding is passed first.</p><p>If the hash table was created in non-randomized mode, the order in which the bindings are enumerated is reproducible between successive runs of the program, and even between minor versions of OCaml. For randomized hash tables, the order of enumeration is entirely random.</p><p>The behavior is not specified if the hash table is modified by <code>f</code> during the iteration.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-length"><a href="#val-length" class="anchor"></a><code><span><span class="keyword">val</span> length : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p><code>Hashtbl.length tbl</code> returns the number of bindings in <code>tbl</code>. It takes constant time. Multiple bindings are counted once each, so <code>Hashtbl.length</code> gives the number of times <code>Hashtbl.iter</code> calls its first argument.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-randomize"><a href="#val-randomize" class="anchor"></a><code><span><span class="keyword">val</span> randomize : <span>unit <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>After a call to <code>Hashtbl.randomize()</code>, hash tables are created in randomized mode by default: <a href="#val-create"><code>create</code></a> returns randomized hash tables, unless the <code>~random:false</code> optional parameter is given. The same effect can be achieved by setting the <code>R</code> parameter in the <code>OCAMLRUNPARAM</code> environment variable.</p><p>It is recommended that applications or Web frameworks that need to protect themselves against the denial-of-service attack described in <a href="#val-create"><code>create</code></a> call <code>Hashtbl.randomize()</code> at initialization time.</p><p>Note that once <code>Hashtbl.randomize()</code> was called, there is no way to revert to the non-randomized default behavior of <a href="#val-create"><code>create</code></a>. This is intentional. Non-randomized hash tables can still be created using <code>Hashtbl.create ~random:false</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_randomized"><a href="#val-is_randomized" class="anchor"></a><code><span><span class="keyword">val</span> is_randomized : <span>unit <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p>Return <code>true</code> if the tables are currently created in randomized mode by default, <code>false</code> otherwise.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.03.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-rebuild"><a href="#val-rebuild" class="anchor"></a><code><span><span class="keyword">val</span> rebuild : <span>?random:bool <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Return a copy of the given hashtable. Unlike <a href="#val-copy"><code>copy</code></a>, <a href="#val-rebuild"><code>rebuild</code></a><code> h</code> re-hashes all the (key, value) entries of the original table <code>h</code>. The returned hash table is randomized if <code>h</code> was randomized, or the optional <code>random</code> parameter is true, or if the default is to create randomized hash tables; see <a href="#val-create"><code>create</code></a> for more information.</p><p><a href="#val-rebuild"><code>rebuild</code></a> can safely be used to import a hash table built by an old version of the <a href="#"><code>Hashtbl</code></a> module, then marshaled to persistent storage. After unmarshaling, apply <a href="#val-rebuild"><code>rebuild</code></a> to produce a hash table for the current version of the <a href="#"><code>Hashtbl</code></a> module.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.12.0</li></ul></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-statistics"><a href="#type-statistics" class="anchor"></a><code><span><span class="keyword">type</span> statistics</span><span> = <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-statistics">Stdlib.Hashtbl.statistics</a></span><span> = </span><span>{</span></code><ol><li id="type-statistics.num_bindings" class="def record field anchored"><a href="#type-statistics.num_bindings" class="anchor"></a><code><span>num_bindings : int;</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>Number of bindings present in the table. Same value as returned by <a href="#val-length"><code>length</code></a>.</p><span class="comment-delim">*)</span></div></li><li id="type-statistics.num_buckets" class="def record field anchored"><a href="#type-statistics.num_buckets" class="anchor"></a><code><span>num_buckets : int;</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>Number of buckets in the table.</p><span class="comment-delim">*)</span></div></li><li id="type-statistics.max_bucket_length" class="def record field anchored"><a href="#type-statistics.max_bucket_length" class="anchor"></a><code><span>max_bucket_length : int;</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>Maximal number of bindings per bucket.</p><span class="comment-delim">*)</span></div></li><li id="type-statistics.bucket_histogram" class="def record field anchored"><a href="#type-statistics.bucket_histogram" class="anchor"></a><code><span>bucket_histogram : <span>int array</span>;</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>Histogram of bucket sizes. This array <code>histo</code> has length <code>max_bucket_length + 1</code>. The value of <code>histo.(i)</code> is the number of buckets whose size is <code>i</code>.</p><span class="comment-delim">*)</span></div></li></ol><code><span>}</span></code></div><div class="spec-doc"><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-stats"><a href="#val-stats" class="anchor"></a><code><span><span class="keyword">val</span> stats : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <a href="#type-statistics">statistics</a></span></code></div><div class="spec-doc"><p><code>Hashtbl.stats tbl</code> returns statistics about the table <code>tbl</code>: number of buckets, size of the biggest bucket, distribution of buckets by size.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00.0</li></ul></div></div><h2 id="hash-tables-and-sequences"><a href="#hash-tables-and-sequences" class="anchor"></a>Hash tables and Sequences</h2><div class="odoc-spec"><div class="spec value anchored" id="val-to_seq"><a href="#val-to_seq" class="anchor"></a><code><span><span class="keyword">val</span> to_seq : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span></span></code></div><div class="spec-doc"><p>Iterate on the whole table. The order in which the bindings appear in the sequence is unspecified. However, if the table contains several bindings for the same key, they appear in reversed order of introduction, that is, the most recent binding appears first.</p><p>The behavior is not specified if the hash table is modified during the iteration.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_seq_keys"><a href="#val-to_seq_keys" class="anchor"></a><code><span><span class="keyword">val</span> to_seq_keys : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">_</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span></span></code></div><div class="spec-doc"><p>Same as <code>Seq.map fst (to_seq m)</code></p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_seq_values"><a href="#val-to_seq_values" class="anchor"></a><code><span><span class="keyword">val</span> to_seq_values : <span><span><span>(<span class="type-var">_</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span></span></code></div><div class="spec-doc"><p>Same as <code>Seq.map snd (to_seq m)</code></p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-replace_seq"><a href="#val-replace_seq" class="anchor"></a><code><span><span class="keyword">val</span> replace_seq : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Add the given bindings to the table, using <a href="#val-replace"><code>replace</code></a></p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><h2 id="functorial-interface"><a href="#functorial-interface" class="anchor"></a>Functorial interface</h2><p>The functorial interface allows the use of specific comparison and hash functions, either for performance/security concerns, or because keys are not hashable/comparable with the polymorphic builtins.</p><p>For instance, one might want to specialize a table for integer keys:</p><pre class="language-ocaml"><code>module IntHash =
|
||
struct
|
||
type t = int
|
||
let equal i j = i=j
|
||
let hash i = i land max_int
|
||
end
|
||
|
||
module IntHashtbl = Hashtbl.Make(IntHash)
|
||
|
||
let h = IntHashtbl.create 17 in
|
||
IntHashtbl.add h 12 "hello"</code></pre><p>This creates a new module <code>IntHashtbl</code>, with a new type <code>'a
|
||
IntHashtbl.t</code> of tables from <code>int</code> to <code>'a</code>. In this example, <code>h</code> contains <code>string</code> values so its type is <code>string IntHashtbl.t</code>.</p><p>Note that the new type <code>'a IntHashtbl.t</code> is not compatible with the type <code>('a,'b) Hashtbl.t</code> of the generic interface. For example, <code>Hashtbl.length h</code> would not type-check, you must use <code>IntHashtbl.length</code>.</p><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-HashedType"><a href="#module-type-HashedType" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-HashedType/index.html">HashedType</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>The 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>The 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> Make</span><span> = <a href="../../../ocaml/Stdlib/Hashtbl/Make/index.html">Stdlib.Hashtbl.Make</a></span></code></div><div class="spec-doc"><p>Functor building an implementation of the hashtable structure. The functor <code>Hashtbl.Make</code> returns a structure containing a type <code>key</code> of keys and a type <code>'a t</code> of hash tables associating data of type <code>'a</code> to keys of type <code>key</code>. The operations perform similarly to those of the generic interface, but use the hashing and equality functions specified in the functor argument <code>H</code> instead of generic equality and hashing. Since the hash function is not seeded, the <code>create</code> operation of the result structure always returns non-randomized hash tables.</p></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-SeededHashedType"><a href="#module-type-SeededHashedType" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-SeededHashedType/index.html">SeededHashedType</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>The input signature of the functor <a href="MakeSeeded/index.html"><code>MakeSeeded</code></a>.</p></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-SeededS"><a href="#module-type-SeededS" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-SeededS/index.html">SeededS</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>The output signature of the functor <a href="MakeSeeded/index.html"><code>MakeSeeded</code></a>.</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-MakeSeeded"><a href="#module-MakeSeeded" class="anchor"></a><code><span><span class="keyword">module</span> <a href="MakeSeeded/index.html">MakeSeeded</a></span><span> (<a href="MakeSeeded/argument-1-H/index.html">H</a> : <a href="module-type-SeededHashedType/index.html">SeededHashedType</a>) : <a href="module-type-SeededS/index.html">SeededS</a> <span class="keyword">with</span> <span><span class="keyword">type</span> <a href="module-type-SeededS/index.html#type-key">key</a> = <a href="MakeSeeded/argument-1-H/index.html#type-t">H.t</a></span></span></code></div><div class="spec-doc"><p>Functor building an implementation of the hashtable structure. The functor <code>Hashtbl.MakeSeeded</code> returns a structure containing a type <code>key</code> of keys and a type <code>'a t</code> of hash tables associating data of type <code>'a</code> to keys of type <code>key</code>. The operations perform similarly to those of the generic interface, but use the seeded hashing and equality functions specified in the functor argument <code>H</code> instead of generic equality and hashing. The <code>create</code> operation of the result structure supports the <code>~</code><code>random</code> optional parameter and returns randomized hash tables if <code>~random:true</code> is passed or if randomization is globally on (see <a href="#val-randomize"><code>Hashtbl.randomize</code></a>).</p></div></div><h2 id="the-polymorphic-hash-functions"><a href="#the-polymorphic-hash-functions" class="anchor"></a>The polymorphic hash functions</h2><div class="odoc-spec"><div class="spec value anchored" id="val-hash"><a href="#val-hash" class="anchor"></a><code><span><span class="keyword">val</span> hash : <span><span class="type-var">'a</span> <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p><code>Hashtbl.hash x</code> associates a nonnegative integer to any value of any type. It is guaranteed that if <code>x = y</code> or <code>Stdlib.compare x y = 0</code>, then <code>hash x = hash y</code>. Moreover, <code>hash</code> always terminates, even on cyclic structures.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-seeded_hash"><a href="#val-seeded_hash" class="anchor"></a><code><span><span class="keyword">val</span> seeded_hash : <span>int <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p>A variant of <a href="#val-hash"><code>hash</code></a> that is further parameterized by an integer seed.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-hash_param"><a href="#val-hash_param" class="anchor"></a><code><span><span class="keyword">val</span> hash_param : <span>int <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p><code>Hashtbl.hash_param meaningful total x</code> computes a hash value for <code>x</code>, with the same properties as for <code>hash</code>. The two extra integer parameters <code>meaningful</code> and <code>total</code> give more precise control over hashing. Hashing performs a breadth-first, left-to-right traversal of the structure <code>x</code>, stopping after <code>meaningful</code> meaningful nodes were encountered, or <code>total</code> nodes (meaningful or not) were encountered. If <code>total</code> as specified by the user exceeds a certain value, currently 256, then it is capped to that value. Meaningful nodes are: integers; floating-point numbers; strings; characters; booleans; and constant constructors. Larger values of <code>meaningful</code> and <code>total</code> means that more nodes are taken into account to compute the final hash value, and therefore collisions are less likely to happen. However, hashing takes longer. The parameters <code>meaningful</code> and <code>total</code> govern the tradeoff between accuracy and speed. As default choices, <a href="#val-hash"><code>hash</code></a> and <a href="#val-seeded_hash"><code>seeded_hash</code></a> take <code>meaningful = 10</code> and <code>total = 100</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-seeded_hash_param"><a href="#val-seeded_hash_param" class="anchor"></a><code><span><span class="keyword">val</span> seeded_hash_param : <span>int <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p>A variant of <a href="#val-hash_param"><code>hash_param</code></a> that is further parameterized by an integer seed. Usage: <code>Hashtbl.seeded_hash_param meaningful total seed x</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00.0</li></ul></div></div></details></div><div class="odoc-include"><details open="open"><summary class="spec include"><code><span><span class="keyword">include</span> <span class="keyword">module</span> <span class="keyword">type</span> <span class="keyword">of</span> <span class="keyword">struct</span> <span class="keyword">include</span> <a href="../../CCHashtbl/Poly/index.html">CCHashtbl.Poly</a> <span class="keyword">end</span></span></code></summary><div class="odoc-spec"><div class="spec value anchored" id="val-get"><a href="#val-get" class="anchor"></a><code><span><span class="keyword">val</span> get : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> option</span></span></code></div><div class="spec-doc"><p><code>get tbl k</code> finds a binding for the key <code>k</code> if present, or returns <code>None</code> if no value is found. Safe version of <a href="#val-find"><code>Hashtbl.find</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_or"><a href="#val-get_or" class="anchor"></a><code><span><span class="keyword">val</span> get_or : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span>default:<span class="type-var">'b</span> <span class="arrow">-></span></span> <span class="type-var">'b</span></span></code></div><div class="spec-doc"><p><code>get_or tbl k ~default</code> returns the value associated to <code>k</code> if present, and returns <code>default</code> otherwise (if <code>k</code> doesn't belong in <code>tbl</code>).</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.16</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-keys"><a href="#val-keys" class="anchor"></a><code><span><span class="keyword">val</span> keys : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="../../CCHashtbl/index.html#type-iter">CCHashtbl.iter</a></span></span></code></div><div class="spec-doc"><p><code>keys tbl f</code> iterates on keys (similar order as <a href="#val-iter"><code>Hashtbl.iter</code></a>).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-values"><a href="#val-values" class="anchor"></a><code><span><span class="keyword">val</span> values : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <a href="../../CCHashtbl/index.html#type-iter">CCHashtbl.iter</a></span></span></code></div><div class="spec-doc"><p><code>values tbl f</code> iterates on values in the table <code>tbl</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-keys_list"><a href="#val-keys_list" class="anchor"></a><code><span><span class="keyword">val</span> keys_list : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> list</span></span></code></div><div class="spec-doc"><p><code>keys_list tbl</code> is the list of keys in <code>tbl</code>. If the key is in the Hashtable multiple times, all occurrences will be returned.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.8</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-values_list"><a href="#val-values_list" class="anchor"></a><code><span><span class="keyword">val</span> values_list : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> list</span></span></code></div><div class="spec-doc"><p><code>values_list tbl</code> is the list of values in <code>tbl</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.8</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-map_list"><a href="#val-map_list" class="anchor"></a><code><span><span class="keyword">val</span> map_list : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span class="type-var">'c</span>)</span> <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'c</span> list</span></span></code></div><div class="spec-doc"><p><code>map_list f tbl</code> maps on a <code>tbl</code>'s items. Collect into a list.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-incr"><a href="#val-incr" class="anchor"></a><code><span><span class="keyword">val</span> incr : <span>?by:int <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span>, int)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>incr ?by tbl x</code> increments or initializes the counter associated with <code>x</code>. If <code>get tbl x = None</code>, then after update, <code>get tbl x = Some 1</code>; otherwise, if <code>get tbl x = Some n</code>, now <code>get tbl x = Some (n+1)</code>.</p><ul class="at-tags"><li class="parameter"><span class="at-tag">parameter</span> <span class="value">by</span> <p>if specified, the int value is incremented by <code>by</code> rather than 1.</p></li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.16</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-decr"><a href="#val-decr" class="anchor"></a><code><span><span class="keyword">val</span> decr : <span>?by:int <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span>, int)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>decr ?by tbl x</code> is like <a href="#val-incr"><code>incr</code></a> but subtract 1 (or the value of <code>by</code>). If the value reaches 0, the key is removed from the table. This does nothing if the key is not already present in the table.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.16</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_iter"><a href="#val-to_iter" class="anchor"></a><code><span><span class="keyword">val</span> to_iter : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../CCHashtbl/index.html#type-iter">CCHashtbl.iter</a></span></span></code></div><div class="spec-doc"><p>Iterate on bindings in the table.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 2.8</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_list"><a href="#val-add_list" class="anchor"></a><code><span><span class="keyword">val</span> add_list : <span><span><span>(<span class="type-var">'a</span>, <span><span class="type-var">'b</span> list</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>add_list tbl x y</code> adds <code>y</code> to the list <code>x</code> is bound to. If <code>x</code> is not bound, it becomes bound to <code>y</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.16</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_iter"><a href="#val-add_iter" class="anchor"></a><code><span><span class="keyword">val</span> add_iter : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../CCHashtbl/index.html#type-iter">CCHashtbl.iter</a></span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Add the corresponding pairs to the table, using <a href="#val-add"><code>Hashtbl.add</code></a>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 2.8</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_iter_with"><a href="#val-add_iter_with" class="anchor"></a><code><span><span class="keyword">val</span> add_iter_with :
|
||
<span>f:<span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span>
|
||
<span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../CCHashtbl/index.html#type-iter">CCHashtbl.iter</a></span> <span class="arrow">-></span></span>
|
||
unit</span></code></div><div class="spec-doc"><p>Add the corresponding pairs to the table, using <a href="#val-add"><code>Hashtbl.add</code></a>. If a key occurs multiple times in the input, the values are combined using <code>f</code> in an unspecified order.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.3</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_seq"><a href="#val-add_seq" class="anchor"></a><code><span><span class="keyword">val</span> add_seq : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Add the corresponding pairs to the table, using <a href="#val-add"><code>Hashtbl.add</code></a>. Renamed from <code>add_std_seq</code> since 3.0.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_seq_with"><a href="#val-add_seq_with" class="anchor"></a><code><span><span class="keyword">val</span> add_seq_with :
|
||
<span>f:<span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span>
|
||
<span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span> <span class="arrow">-></span></span>
|
||
unit</span></code></div><div class="spec-doc"><p>Add the corresponding pairs to the table. If a key occurs multiple times in the input, the values are combined using <code>f</code> in an unspecified order.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.3</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_iter"><a href="#val-of_iter" class="anchor"></a><code><span><span class="keyword">val</span> of_iter : <span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../CCHashtbl/index.html#type-iter">CCHashtbl.iter</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></code></div><div class="spec-doc"><p>From the given bindings, added in order.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 2.8</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_iter_with"><a href="#val-of_iter_with" class="anchor"></a><code><span><span class="keyword">val</span> of_iter_with :
|
||
<span>f:<span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../CCHashtbl/index.html#type-iter">CCHashtbl.iter</a></span> <span class="arrow">-></span></span>
|
||
<span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></code></div><div class="spec-doc"><p>From the given bindings, added in order. If a key occurs multiple times in the input, the values are combined using <code>f</code> in an unspecified order.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.3</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_seq"><a href="#val-of_seq" class="anchor"></a><code><span><span class="keyword">val</span> of_seq : <span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></code></div><div class="spec-doc"><p>From the given bindings, added in order. Renamed from <code>of_std_seq</code> since 3.0.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_seq_with"><a href="#val-of_seq_with" class="anchor"></a><code><span><span class="keyword">val</span> of_seq_with :
|
||
<span>f:<span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span> <span class="arrow">-></span></span>
|
||
<span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></code></div><div class="spec-doc"><p>From the given bindings, added in order. If a key occurs multiple times in the input, the values are combined using <code>f</code> in an unspecified order.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.3</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_iter_count"><a href="#val-add_iter_count" class="anchor"></a><code><span><span class="keyword">val</span> add_iter_count : <span><span><span>(<span class="type-var">'a</span>, int)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span><span class="type-var">'a</span> <a href="../../CCHashtbl/index.html#type-iter">CCHashtbl.iter</a></span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>add_iter_count tbl i</code> increments the count of each element of <code>i</code> by calling <a href="#val-incr"><code>incr</code></a>. This is useful for counting how many times each element of <code>i</code> occurs.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 2.8</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_seq_count"><a href="#val-add_seq_count" class="anchor"></a><code><span><span class="keyword">val</span> add_seq_count : <span><span><span>(<span class="type-var">'a</span>, int)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span><span class="type-var">'a</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>add_seq_count tbl seq</code> increments the count of each element of <code>seq</code> by calling <a href="#val-incr"><code>incr</code></a>. This is useful for counting how many times each element of <code>seq</code> occurs. Renamed from <code>add_std_seq_count</code> since 3.0.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_iter_count"><a href="#val-of_iter_count" class="anchor"></a><code><span><span class="keyword">val</span> of_iter_count : <span><span><span class="type-var">'a</span> <a href="../../CCHashtbl/index.html#type-iter">CCHashtbl.iter</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span>, int)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></code></div><div class="spec-doc"><p>Like <a href="#val-add_seq_count"><code>add_seq_count</code></a>, but allocates a new table and returns it.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 2.8</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_seq_count"><a href="#val-of_seq_count" class="anchor"></a><code><span><span class="keyword">val</span> of_seq_count : <span><span><span class="type-var">'a</span> <a href="../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span>, int)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></code></div><div class="spec-doc"><p>Like <a href="#val-add_seq_count"><code>add_seq_count</code></a>, but allocates a new table and returns it. Renamed from <code>of_std_seq_count</code> since 3.0.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_list"><a href="#val-to_list" class="anchor"></a><code><span><span class="keyword">val</span> to_list : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> list</span></span></code></div><div class="spec-doc"><p><code>to_list tbl</code> returns the list of (key,value) bindings (order unspecified).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_list"><a href="#val-of_list" class="anchor"></a><code><span><span class="keyword">val</span> of_list : <span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> list</span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></code></div><div class="spec-doc"><p><code>of_list l</code> builds a table from the given list <code>l</code> of bindings <code>k_i -> v_i</code>, added in order using <a href="#val-add"><code>add</code></a>. If a key occurs several times, it will be added several times, and the visible binding will be the last one.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_list_with"><a href="#val-of_list_with" class="anchor"></a><code><span><span class="keyword">val</span> of_list_with :
|
||
<span>f:<span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span>
|
||
<span><span><span>(<span class="type-var">'a</span> * <span class="type-var">'b</span>)</span> list</span> <span class="arrow">-></span></span>
|
||
<span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span></span></code></div><div class="spec-doc"><p>From the given bindings, added in order. If a key occurs multiple times in the input, the values are combined using <code>f</code> in an unspecified order.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.3</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-update"><a href="#val-update" class="anchor"></a><code><span><span class="keyword">val</span> update :
|
||
<span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span>
|
||
<span>f:<span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span><span><span class="type-var">'b</span> option</span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> option</span>)</span> <span class="arrow">-></span></span>
|
||
<span>k:<span class="type-var">'a</span> <span class="arrow">-></span></span>
|
||
unit</span></code></div><div class="spec-doc"><p><code>update tbl ~f ~k</code> updates key <code>k</code> by calling <code>f k (Some v)</code> if <code>k</code> was mapped to <code>v</code>, or <code>f k None</code> otherwise; if the call returns <code>None</code> then <code>k</code> is removed/stays removed, if the call returns <code>Some v'</code> then the binding <code>k -> v'</code> is inserted using <a href="#val-replace"><code>Hashtbl.replace</code></a>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.14</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_or_add"><a href="#val-get_or_add" class="anchor"></a><code><span><span class="keyword">val</span> get_or_add : <span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <span class="arrow">-></span></span> <span>f:<span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span> <span>k:<span class="type-var">'a</span> <span class="arrow">-></span></span> <span class="type-var">'b</span></span></code></div><div class="spec-doc"><p><code>get_or_add tbl ~k ~f</code> finds and returns the binding of <code>k</code> in <code>tbl</code>, if it exists. If it does not exist, then <code>f k</code> is called to obtain a new binding <code>v</code>; <code>k -> v</code> is added to <code>tbl</code> and <code>v</code> is returned.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 1.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pp"><a href="#val-pp" class="anchor"></a><code><span><span class="keyword">val</span> pp :
|
||
<span>?pp_start:<span>unit <a href="../../CCHashtbl/index.html#type-printer">CCHashtbl.printer</a></span> <span class="arrow">-></span></span>
|
||
<span>?pp_stop:<span>unit <a href="../../CCHashtbl/index.html#type-printer">CCHashtbl.printer</a></span> <span class="arrow">-></span></span>
|
||
<span>?pp_sep:<span>unit <a href="../../CCHashtbl/index.html#type-printer">CCHashtbl.printer</a></span> <span class="arrow">-></span></span>
|
||
<span>?pp_arrow:<span>unit <a href="../../CCHashtbl/index.html#type-printer">CCHashtbl.printer</a></span> <span class="arrow">-></span></span>
|
||
<span><span><span class="type-var">'a</span> <a href="../../CCHashtbl/index.html#type-printer">CCHashtbl.printer</a></span> <span class="arrow">-></span></span>
|
||
<span><span><span class="type-var">'b</span> <a href="../../CCHashtbl/index.html#type-printer">CCHashtbl.printer</a></span> <span class="arrow">-></span></span>
|
||
<span><span><span>(<span class="type-var">'a</span>, <span class="type-var">'b</span>)</span> <a href="../../../ocaml/Stdlib/Hashtbl/index.html#type-t">Stdlib.Hashtbl.t</a></span> <a href="../../CCHashtbl/index.html#type-printer">CCHashtbl.printer</a></span></span></code></div><div class="spec-doc"><p><code>pp ~pp_start ~pp_stop ~pp_sep ~pp arrow pp_k pp_v</code> returns a table printer given a <code>pp_k</code> printer for individual key and a <code>pp_v</code> printer for individual value. <code>pp_start</code> and <code>pp_stop</code> control the opening and closing delimiters, by default print nothing. <code>pp_sep</code> control the separator between binding. <code>pp_arrow</code> control the arrow between the key and value. Renamed from <code>print</code> since 2.0.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.13</li></ul></div></div></details></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> S'</span><span> = <a href="../../CCHashtbl/module-type-S/index.html">CCHashtbl.S</a></span></code></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> Make'</span><span> = <a href="../../CCHashtbl/Make/index.html">CCHashtbl.Make</a></span></code></div></div></div></body></html> |