mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
246 lines
No EOL
17 KiB
HTML
246 lines
No EOL
17 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" href="style.css" type="text/css">
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
<link rel="Start" href="index.html">
|
|
<link rel="previous" href="CCString.html">
|
|
<link rel="next" href="CCMap.html">
|
|
<link rel="Up" href="index.html">
|
|
<link title="Index of types" rel=Appendix href="index_types.html">
|
|
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
|
|
<link title="Index of values" rel=Appendix href="index_values.html">
|
|
<link title="Index of class methods" rel=Appendix href="index_methods.html">
|
|
<link title="Index of class types" rel=Appendix href="index_class_types.html">
|
|
<link title="Index of modules" rel=Appendix href="index_modules.html">
|
|
<link title="Index of module types" rel=Appendix href="index_module_types.html">
|
|
<link title="CCVector" rel="Chapter" href="CCVector.html">
|
|
<link title="CCPrint" rel="Chapter" href="CCPrint.html">
|
|
<link title="CCError" rel="Chapter" href="CCError.html">
|
|
<link title="CCHeap" rel="Chapter" href="CCHeap.html">
|
|
<link title="CCList" rel="Chapter" href="CCList.html">
|
|
<link title="CCOpt" rel="Chapter" href="CCOpt.html">
|
|
<link title="CCPair" rel="Chapter" href="CCPair.html">
|
|
<link title="CCFun" rel="Chapter" href="CCFun.html">
|
|
<link title="CCHash" rel="Chapter" href="CCHash.html">
|
|
<link title="CCInt" rel="Chapter" href="CCInt.html">
|
|
<link title="CCBool" rel="Chapter" href="CCBool.html">
|
|
<link title="CCFloat" rel="Chapter" href="CCFloat.html">
|
|
<link title="CCArray" rel="Chapter" href="CCArray.html">
|
|
<link title="CCRef" rel="Chapter" href="CCRef.html">
|
|
<link title="CCSet" rel="Chapter" href="CCSet.html">
|
|
<link title="CCOrd" rel="Chapter" href="CCOrd.html">
|
|
<link title="CCRandom" rel="Chapter" href="CCRandom.html">
|
|
<link title="CCString" rel="Chapter" href="CCString.html">
|
|
<link title="CCHashtbl" rel="Chapter" href="CCHashtbl.html">
|
|
<link title="CCMap" rel="Chapter" href="CCMap.html">
|
|
<link title="CCFormat" rel="Chapter" href="CCFormat.html">
|
|
<link title="CCIO" rel="Chapter" href="CCIO.html">
|
|
<link title="CCInt64" rel="Chapter" href="CCInt64.html">
|
|
<link title="CCChar" rel="Chapter" href="CCChar.html">
|
|
<link title="CCResult" rel="Chapter" href="CCResult.html">
|
|
<link title="Containers" rel="Chapter" href="Containers.html">
|
|
<link title="CCKTree" rel="Chapter" href="CCKTree.html">
|
|
<link title="CCKList" rel="Chapter" href="CCKList.html">
|
|
<link title="CCLazy_list" rel="Chapter" href="CCLazy_list.html">
|
|
<link title="CCMultiMap" rel="Chapter" href="CCMultiMap.html">
|
|
<link title="CCMultiSet" rel="Chapter" href="CCMultiSet.html">
|
|
<link title="CCTrie" rel="Chapter" href="CCTrie.html">
|
|
<link title="CCFlatHashtbl" rel="Chapter" href="CCFlatHashtbl.html">
|
|
<link title="CCCache" rel="Chapter" href="CCCache.html">
|
|
<link title="CCPersistentHashtbl" rel="Chapter" href="CCPersistentHashtbl.html">
|
|
<link title="CCDeque" rel="Chapter" href="CCDeque.html">
|
|
<link title="CCFQueue" rel="Chapter" href="CCFQueue.html">
|
|
<link title="CCBV" rel="Chapter" href="CCBV.html">
|
|
<link title="CCMixtbl" rel="Chapter" href="CCMixtbl.html">
|
|
<link title="CCMixmap" rel="Chapter" href="CCMixmap.html">
|
|
<link title="CCRingBuffer" rel="Chapter" href="CCRingBuffer.html">
|
|
<link title="CCIntMap" rel="Chapter" href="CCIntMap.html">
|
|
<link title="CCPersistentArray" rel="Chapter" href="CCPersistentArray.html">
|
|
<link title="CCMixset" rel="Chapter" href="CCMixset.html">
|
|
<link title="CCHashconsedSet" rel="Chapter" href="CCHashconsedSet.html">
|
|
<link title="CCGraph" rel="Chapter" href="CCGraph.html">
|
|
<link title="CCHashSet" rel="Chapter" href="CCHashSet.html">
|
|
<link title="CCBitField" rel="Chapter" href="CCBitField.html">
|
|
<link title="CCHashTrie" rel="Chapter" href="CCHashTrie.html">
|
|
<link title="CCBloom" rel="Chapter" href="CCBloom.html">
|
|
<link title="CCWBTree" rel="Chapter" href="CCWBTree.html">
|
|
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
|
|
<link title="CCAllocCache" rel="Chapter" href="CCAllocCache.html">
|
|
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
|
|
<link title="CCHet" rel="Chapter" href="CCHet.html">
|
|
<link title="Containers_string" rel="Chapter" href="Containers_string.html">
|
|
<link title="CCKMP" rel="Chapter" href="CCKMP.html">
|
|
<link title="CCLevenshtein" rel="Chapter" href="CCLevenshtein.html">
|
|
<link title="CCApp_parse" rel="Chapter" href="CCApp_parse.html">
|
|
<link title="CCParse" rel="Chapter" href="CCParse.html">
|
|
<link title="CCBigstring" rel="Chapter" href="CCBigstring.html">
|
|
<link title="CCArray1" rel="Chapter" href="CCArray1.html">
|
|
<link title="CCPool" rel="Chapter" href="CCPool.html">
|
|
<link title="CCLock" rel="Chapter" href="CCLock.html">
|
|
<link title="CCSemaphore" rel="Chapter" href="CCSemaphore.html">
|
|
<link title="CCThread" rel="Chapter" href="CCThread.html">
|
|
<link title="CCBlockingQueue" rel="Chapter" href="CCBlockingQueue.html">
|
|
<link title="CCTimer" rel="Chapter" href="CCTimer.html">
|
|
<link title="Containers_advanced" rel="Chapter" href="Containers_advanced.html">
|
|
<link title="CCLinq" rel="Chapter" href="CCLinq.html">
|
|
<link title="CCBatch" rel="Chapter" href="CCBatch.html">
|
|
<link title="CCCat" rel="Chapter" href="CCCat.html">
|
|
<link title="CCMonadIO" rel="Chapter" href="CCMonadIO.html">
|
|
<link title="Containers_io_is_deprecated" rel="Chapter" href="Containers_io_is_deprecated.html">
|
|
<link title="CCUnix" rel="Chapter" href="CCUnix.html">
|
|
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
|
|
<link title="CCSexpM" rel="Chapter" href="CCSexpM.html"><link title="Polymorphic tables" rel="Section" href="#2_Polymorphictables">
|
|
<link title="Functor" rel="Section" href="#2_Functor">
|
|
<link title="Default Table" rel="Section" href="#2_DefaultTable">
|
|
<link title="Count occurrences using a Hashtbl" rel="Section" href="#2_CountoccurrencesusingaHashtbl">
|
|
<title>Containers doc : CCHashtbl</title>
|
|
</head>
|
|
<body>
|
|
<div class="navbar"><a class="pre" href="CCString.html" title="CCString">Previous</a>
|
|
<a class="up" href="index.html" title="Index">Up</a>
|
|
<a class="post" href="CCMap.html" title="CCMap">Next</a>
|
|
</div>
|
|
<h1>Module <a href="type_CCHashtbl.html">CCHashtbl</a></h1>
|
|
|
|
<pre><span class="keyword">module</span> CCHashtbl: <code class="code"><span class="keyword">sig</span></code> <a href="CCHashtbl.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
|
|
<h1 id="1_ExtensiontothestandardHashtbl">Extension to the standard Hashtbl</h1><br>
|
|
<b>Since</b> 0.4<br>
|
|
</div>
|
|
<hr width="100%">
|
|
|
|
<pre><span id="TYPEsequence"><span class="keyword">type</span> <code class="type">'a</code> sequence</span> = <code class="type">('a -> unit) -> unit</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEeq"><span class="keyword">type</span> <code class="type">'a</code> eq</span> = <code class="type">'a -> 'a -> bool</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEhash"><span class="keyword">type</span> <code class="type">'a</code> hash</span> = <code class="type">'a -> int</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEprinter"><span class="keyword">type</span> <code class="type">'a</code> printer</span> = <code class="type">Format.formatter -> 'a -> unit</code> </pre>
|
|
|
|
<br>
|
|
<h2 id="2_Polymorphictables">Polymorphic tables</h2><br>
|
|
|
|
<pre><span id="VALget"><span class="keyword">val</span> get</span> : <code class="type">('a, 'b) Hashtbl.t -> 'a -> 'b option</code></pre><div class="info ">
|
|
Safe version of <code class="code"><span class="constructor">Hashtbl</span>.find</code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALget_or"><span class="keyword">val</span> get_or</span> : <code class="type">('a, 'b) Hashtbl.t -> 'a -> or_:'b -> 'b</code></pre><div class="info ">
|
|
<code class="code">get_or tbl k ~or_</code> returns the value associated to <code class="code">k</code> if present,
|
|
and returns <code class="code">or_</code> otherwise (if <code class="code">k</code> doesn't belong in <code class="code">tbl</code>)<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALkeys"><span class="keyword">val</span> keys</span> : <code class="type">('a, 'b) Hashtbl.t -> 'a <a href="CCHashtbl.html#TYPEsequence">sequence</a></code></pre><div class="info ">
|
|
Iterate on keys (similar order as <code class="code"><span class="constructor">Hashtbl</span>.iter</code>)<br>
|
|
</div>
|
|
|
|
<pre><span id="VALvalues"><span class="keyword">val</span> values</span> : <code class="type">('a, 'b) Hashtbl.t -> 'b <a href="CCHashtbl.html#TYPEsequence">sequence</a></code></pre><div class="info ">
|
|
Iterate on values in the table<br>
|
|
</div>
|
|
|
|
<pre><span id="VALkeys_list"><span class="keyword">val</span> keys_list</span> : <code class="type">('a, 'b) Hashtbl.t -> 'a list</code></pre><div class="info ">
|
|
<code class="code">keys_list t</code> is the list of keys in <code class="code">t</code>.<br>
|
|
<b>Since</b> 0.8<br>
|
|
</div>
|
|
|
|
<pre><span id="VALvalues_list"><span class="keyword">val</span> values_list</span> : <code class="type">('a, 'b) Hashtbl.t -> 'b list</code></pre><div class="info ">
|
|
<code class="code">values_list t</code> is the list of values in <code class="code">t</code>.<br>
|
|
<b>Since</b> 0.8<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmap_list"><span class="keyword">val</span> map_list</span> : <code class="type">('a -> 'b -> 'c) -> ('a, 'b) Hashtbl.t -> 'c list</code></pre><div class="info ">
|
|
Map on a hashtable's items, collect into a list<br>
|
|
</div>
|
|
|
|
<pre><span id="VALincr"><span class="keyword">val</span> incr</span> : <code class="type">?by:int -> ('a, int) Hashtbl.t -> 'a -> unit</code></pre><div class="info ">
|
|
<code class="code">incr ?by tbl x</code> increments or initializes the counter associated with <code class="code">x</code>.
|
|
If <code class="code">get tbl x = <span class="constructor">None</span></code>, then after update, <code class="code">get tbl x = <span class="constructor">Some</span> 1</code>;
|
|
otherwise, if <code class="code">get tbl x = <span class="constructor">Some</span> n</code>, now <code class="code">get tbl x = <span class="constructor">Some</span> (n+1)</code>.<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">by</code> : if specified, the int value is incremented by <code class="code">by</code> rather than 1</div>
|
|
|
|
<pre><span id="VALdecr"><span class="keyword">val</span> decr</span> : <code class="type">?by:int -> ('a, int) Hashtbl.t -> 'a -> unit</code></pre><div class="info ">
|
|
Same as <a href="CCHashtbl.html#VALincr"><code class="code"><span class="constructor">CCHashtbl</span>.incr</code></a> but substract 1 (or the value of <code class="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.<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALto_seq"><span class="keyword">val</span> to_seq</span> : <code class="type">('a, 'b) Hashtbl.t -> ('a * 'b) <a href="CCHashtbl.html#TYPEsequence">sequence</a></code></pre><div class="info ">
|
|
Iterate on bindings in the table<br>
|
|
</div>
|
|
|
|
<pre><span id="VALadd_list"><span class="keyword">val</span> add_list</span> : <code class="type">('a, 'b list) Hashtbl.t -> 'a -> 'b -> unit</code></pre><div class="info ">
|
|
<code class="code">add_list tbl x y</code> adds <code class="code">y</code> to the list <code class="code">x</code> is bound to. If <code class="code">x</code> is
|
|
not bound, it becomes bound to <code class="code">[y]</code>.<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALadd_seq"><span class="keyword">val</span> add_seq</span> : <code class="type">('a, 'b) Hashtbl.t -> ('a * 'b) <a href="CCHashtbl.html#TYPEsequence">sequence</a> -> unit</code></pre><div class="info ">
|
|
Add the corresponding pairs to the table, using <code class="code"><span class="constructor">Hashtbl</span>.add</code>.<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALof_seq"><span class="keyword">val</span> of_seq</span> : <code class="type">('a * 'b) <a href="CCHashtbl.html#TYPEsequence">sequence</a> -> ('a, 'b) Hashtbl.t</code></pre><div class="info ">
|
|
From the given bindings, added in order<br>
|
|
</div>
|
|
|
|
<pre><span id="VALadd_seq_count"><span class="keyword">val</span> add_seq_count</span> : <code class="type">('a, int) Hashtbl.t -> 'a <a href="CCHashtbl.html#TYPEsequence">sequence</a> -> unit</code></pre><div class="info ">
|
|
<code class="code">add_seq_count tbl seq</code> increments the count of each element of <code class="code">seq</code>
|
|
by calling <a href="CCHashtbl.html#VALincr"><code class="code"><span class="constructor">CCHashtbl</span>.incr</code></a>. This is useful for counting how many times each
|
|
element of <code class="code">seq</code> occurs.<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALof_seq_count"><span class="keyword">val</span> of_seq_count</span> : <code class="type">'a <a href="CCHashtbl.html#TYPEsequence">sequence</a> -> ('a, int) Hashtbl.t</code></pre><div class="info ">
|
|
Similar to <a href="CCHashtbl.html#VALadd_seq_count"><code class="code"><span class="constructor">CCHashtbl</span>.add_seq_count</code></a>, but allocates a new table and returns it<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALto_list"><span class="keyword">val</span> to_list</span> : <code class="type">('a, 'b) Hashtbl.t -> ('a * 'b) list</code></pre><div class="info ">
|
|
List of bindings (order unspecified)<br>
|
|
</div>
|
|
|
|
<pre><span id="VALof_list"><span class="keyword">val</span> of_list</span> : <code class="type">('a * 'b) list -> ('a, 'b) Hashtbl.t</code></pre><div class="info ">
|
|
From the given list of bindings, added in order<br>
|
|
</div>
|
|
|
|
<pre><span id="VALupdate"><span class="keyword">val</span> update</span> : <code class="type">('a, 'b) Hashtbl.t -> f:('a -> 'b option -> 'b option) -> k:'a -> unit</code></pre><div class="info ">
|
|
<code class="code">update tbl ~f ~k</code> updates key <code class="code">k</code> by calling <code class="code">f k (<span class="constructor">Some</span> v)</code> if
|
|
<code class="code">k</code> was mapped to <code class="code">v</code>, or <code class="code">f k <span class="constructor">None</span></code> otherwise; if the call
|
|
returns <code class="code"><span class="constructor">None</span></code> then <code class="code">k</code> is removed/stays removed, if the call
|
|
returns <code class="code"><span class="constructor">Some</span> v'</code> then the binding <code class="code">k <span class="keywordsign">-></span> v'</code> is inserted
|
|
using <code class="code"><span class="constructor">Hashtbl</span>.replace</code><br>
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALprint"><span class="keyword">val</span> print</span> : <code class="type">'a <a href="CCHashtbl.html#TYPEprinter">printer</a> -><br> 'b <a href="CCHashtbl.html#TYPEprinter">printer</a> -> ('a, 'b) Hashtbl.t <a href="CCHashtbl.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Printer for table<br>
|
|
<b>Since</b> 0.13<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Functor">Functor</h2><br>
|
|
|
|
<pre><span class="keyword">module type</span> <a href="CCHashtbl.S.html">S</a> = <code class="code"><span class="keyword">sig</span></code> <a href="CCHashtbl.S.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
|
|
<pre><span class="keyword">module</span> <a href="CCHashtbl.Make.html">Make</a> <code class="code">(</code><code class="code"><span class="constructor">X</span></code><code class="code"> : </code><code class="type">Hashtbl.HashedType</code><code class="code">) </code>: <code class="type"><a href="CCHashtbl.S.html">S</a></code><code class="type"> with type key = X.t and type 'a t = 'a Hashtbl.Make(X).t</code></pre><br>
|
|
<h2 id="2_DefaultTable">Default Table</h2>
|
|
<p>
|
|
|
|
A table with a default element for keys that were never added.<br>
|
|
|
|
<pre><span class="keyword">module type</span> <a href="CCHashtbl.DEFAULT.html">DEFAULT</a> = <code class="code"><span class="keyword">sig</span></code> <a href="CCHashtbl.DEFAULT.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
|
|
<pre><span class="keyword">module</span> <a href="CCHashtbl.MakeDefault.html">MakeDefault</a> <code class="code">(</code><code class="code"><span class="constructor">X</span></code><code class="code"> : </code><code class="type">Hashtbl.HashedType</code><code class="code">) </code>: <code class="type"><a href="CCHashtbl.DEFAULT.html">DEFAULT</a></code><code class="type"> with type key = X.t</code></pre><br>
|
|
<h2 id="2_CountoccurrencesusingaHashtbl">Count occurrences using a Hashtbl</h2><br>
|
|
|
|
<pre><span class="keyword">module type</span> <a href="CCHashtbl.COUNTER.html">COUNTER</a> = <code class="code"><span class="keyword">sig</span></code> <a href="CCHashtbl.COUNTER.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
|
|
<pre><span class="keyword">module</span> <a href="CCHashtbl.MakeCounter.html">MakeCounter</a> <code class="code">(</code><code class="code"><span class="constructor">X</span></code><code class="code"> : </code><code class="type">Hashtbl.HashedType</code><code class="code">) </code>: <code class="type"><a href="CCHashtbl.COUNTER.html">COUNTER</a></code><code class="type">
|
|
with type elt = X.t
|
|
and type t = int Hashtbl.Make(X).t</code></pre><div class="info">
|
|
Create a new counter type
|
|
The type <code class="code">t</code> is exposed
|
|
</div>
|
|
</body></html> |