ocaml-containers/dev/CCMixtbl.html
2017-08-25 15:18:48 +02:00

224 lines
No EOL
14 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">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="Start" href="index.html">
<link rel="previous" href="CCBV.html">
<link rel="next" href="CCMixmap.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="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="CCParse" rel="Chapter" href="CCParse.html">
<link title="CCArray_slice" rel="Chapter" href="CCArray_slice.html">
<link title="CCListLabels" rel="Chapter" href="CCListLabels.html">
<link title="CCArrayLabels" rel="Chapter" href="CCArrayLabels.html">
<link title="CCEqual" rel="Chapter" href="CCEqual.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="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="CCWBTree" rel="Chapter" href="CCWBTree.html">
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
<link title="CCSimple_queue" rel="Chapter" href="CCSimple_queue.html">
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
<link title="CCHet" rel="Chapter" href="CCHet.html">
<link title="CCZipper" rel="Chapter" href="CCZipper.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="CCUnix" rel="Chapter" href="CCUnix.html">
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
<link title="CCSexp_lex" rel="Chapter" href="CCSexp_lex.html"><link title="Iterators" rel="Section" href="#2_Iterators">
<title>Containers doc : CCMixtbl</title>
</head>
<body>
<div class="navbar"><a class="pre" href="CCBV.html" title="CCBV">Previous</a>
&nbsp;<a class="up" href="index.html" title="Index">Up</a>
&nbsp;<a class="post" href="CCMixmap.html" title="CCMixmap">Next</a>
</div>
<h1>Module <a href="type_CCMixtbl.html">CCMixtbl</a></h1>
<pre><span class="keyword">module</span> CCMixtbl: <code class="code"><span class="keyword">sig</span></code> <a href="CCMixtbl.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<h1 id="1_HashTablewithHeterogeneousKeys">Hash Table with Heterogeneous Keys</h1>
<p>
From https://github.com/mjambon/mixtbl (thanks to him).
Example:
<p>
<pre class="codepre"><code class="code"> <span class="keyword">let</span> inj_int = <span class="constructor">CCMixtbl</span>.create_inj () ;;
<span class="keyword">let</span> tbl = <span class="constructor">CCMixtbl</span>.create 10 ;;
<span class="constructor">OUnit</span>.assert_equal <span class="constructor">None</span> (<span class="constructor">CCMixtbl</span>.get ~inj:inj_int tbl <span class="string">"a"</span>);;
<span class="constructor">CCMixtbl</span>.set inj_int tbl <span class="string">"a"</span> 1;;
<span class="constructor">OUnit</span>.assert_equal (<span class="constructor">Some</span> 1) (<span class="constructor">CCMixtbl</span>.get ~inj:inj_int tbl <span class="string">"a"</span>);;
<span class="keyword">let</span> inj_string = <span class="constructor">CCMixtbl</span>.create_inj () ;;
<span class="constructor">CCMixtbl</span>.set inj_string tbl <span class="string">"b"</span> <span class="string">"Hello"</span>;
<span class="constructor">OUnit</span>.assert_equal (<span class="constructor">Some</span> <span class="string">"Hello"</span>) (<span class="constructor">CCMixtbl</span>.get inj_string tbl <span class="string">"b"</span>);;
<span class="constructor">OUnit</span>.assert_equal <span class="constructor">None</span> (<span class="constructor">CCMixtbl</span>.get inj_string tbl <span class="string">"a"</span>);;
<span class="constructor">OUnit</span>.assert_equal (<span class="constructor">Some</span> 1) (<span class="constructor">CCMixtbl</span>.get inj_int tbl <span class="string">"a"</span>);;
<span class="constructor">CCMixtbl</span>.set inj_string tbl <span class="string">"a"</span> <span class="string">"Bye"</span>;;
<span class="constructor">OUnit</span>.assert_equal <span class="constructor">None</span> (<span class="constructor">CCMixtbl</span>.get inj_int tbl <span class="string">"a"</span>);;
<span class="constructor">OUnit</span>.assert_equal (<span class="constructor">Some</span> <span class="string">"Bye"</span>) (<span class="constructor">CCMixtbl</span>.get inj_string tbl <span class="string">"a"</span>);;
</code></pre><br>
<b>Since</b> 0.6<br>
</div>
<hr width="100%">
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">'a</code> t</span> </pre>
<div class="info ">
A hash table containing values of different types.
The type parameter <code class="code"><span class="keywordsign">'</span>a</code> represents the type of the keys.<br>
</div>
<pre><span id="TYPEinjection"><span class="keyword">type</span> <code class="type">'b</code> injection</span> </pre>
<div class="info ">
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.<br>
</div>
<pre><span id="VALcreate"><span class="keyword">val</span> create</span> : <code class="type">int -> 'a <a href="CCMixtbl.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">create&nbsp;n</code> creates a hash table of initial size <code class="code">n</code>.<br>
</div>
<pre><span id="VALcreate_inj"><span class="keyword">val</span> create_inj</span> : <code class="type">unit -> 'b <a href="CCMixtbl.html#TYPEinjection">injection</a></code></pre><div class="info ">
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).<br>
</div>
<pre><span id="VALget"><span class="keyword">val</span> get</span> : <code class="type">inj:'b <a href="CCMixtbl.html#TYPEinjection">injection</a> -> 'a <a href="CCMixtbl.html#TYPEt">t</a> -> 'a -> 'b option</code></pre><div class="info ">
Get the value corresponding to this key, if it exists and
belongs to the same key<br>
</div>
<pre><span id="VALset"><span class="keyword">val</span> set</span> : <code class="type">inj:'b <a href="CCMixtbl.html#TYPEinjection">injection</a> -> 'a <a href="CCMixtbl.html#TYPEt">t</a> -> 'a -> 'b -> unit</code></pre><div class="info ">
Bind the key to the value, using <code class="code">inj</code><br>
</div>
<pre><span id="VALfind"><span class="keyword">val</span> find</span> : <code class="type">inj:'b <a href="CCMixtbl.html#TYPEinjection">injection</a> -> 'a <a href="CCMixtbl.html#TYPEt">t</a> -> 'a -> 'b</code></pre><div class="info ">
Find the value for the given key, which must be of the right type.<br>
<b>Raises</b> <code>Not_found</code> if either the key is not found, or if its value
doesn't belong to the right type<br>
</div>
<pre><span id="VALlength"><span class="keyword">val</span> length</span> : <code class="type">'a <a href="CCMixtbl.html#TYPEt">t</a> -> int</code></pre><div class="info ">
Number of bindings<br>
</div>
<pre><span id="VALclear"><span class="keyword">val</span> clear</span> : <code class="type">'a <a href="CCMixtbl.html#TYPEt">t</a> -> unit</code></pre><div class="info ">
Clear content of the hashtable<br>
</div>
<pre><span id="VALremove"><span class="keyword">val</span> remove</span> : <code class="type">'a <a href="CCMixtbl.html#TYPEt">t</a> -> 'a -> unit</code></pre><div class="info ">
Remove the binding for this key<br>
</div>
<pre><span id="VALcopy"><span class="keyword">val</span> copy</span> : <code class="type">'a <a href="CCMixtbl.html#TYPEt">t</a> -> 'a <a href="CCMixtbl.html#TYPEt">t</a></code></pre><div class="info ">
Copy of the table<br>
</div>
<pre><span id="VALmem"><span class="keyword">val</span> mem</span> : <code class="type">inj:'b <a href="CCMixtbl.html#TYPEinjection">injection</a> -> 'a <a href="CCMixtbl.html#TYPEt">t</a> -> 'a -> bool</code></pre><div class="info ">
Is the given key in the table, with the right type?<br>
</div>
<pre><span id="VALiter_keys"><span class="keyword">val</span> iter_keys</span> : <code class="type">'a <a href="CCMixtbl.html#TYPEt">t</a> -> ('a -> unit) -> unit</code></pre><div class="info ">
Iterate on the keys of this table<br>
</div>
<pre><span id="VALfold_keys"><span class="keyword">val</span> fold_keys</span> : <code class="type">'a <a href="CCMixtbl.html#TYPEt">t</a> -> 'b -> ('b -> 'a -> 'b) -> 'b</code></pre><div class="info ">
Fold over the keys<br>
</div>
<br>
<h2 id="2_Iterators">Iterators</h2><br>
<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="VALkeys_seq"><span class="keyword">val</span> keys_seq</span> : <code class="type">'a <a href="CCMixtbl.html#TYPEt">t</a> -> 'a <a href="CCMixtbl.html#TYPEsequence">sequence</a></code></pre><div class="info ">
All the keys<br>
</div>
<pre><span id="VALbindings_of"><span class="keyword">val</span> bindings_of</span> : <code class="type">inj:'b <a href="CCMixtbl.html#TYPEinjection">injection</a> -> 'a <a href="CCMixtbl.html#TYPEt">t</a> -> ('a * 'b) <a href="CCMixtbl.html#TYPEsequence">sequence</a></code></pre><div class="info ">
All the bindings that come from the corresponding injection<br>
</div>
<pre><code><span id="TYPEvalue"><span class="keyword">type</span> <code class="type"></code>value</span> = </code></pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTvalue.Value"><span class="constructor">Value</span></span> <span class="keyword">:</span> <code class="type">('b <a href="CCMixtbl.html#TYPEinjection">injection</a> -> 'b option)</code> <span class="keyword">-></span> <code class="type"><a href="CCMixtbl.html#TYPEvalue">value</a></code></code></td>
</tr></table>
<pre><span id="VALbindings"><span class="keyword">val</span> bindings</span> : <code class="type">'a <a href="CCMixtbl.html#TYPEt">t</a> -> ('a * <a href="CCMixtbl.html#TYPEvalue">value</a>) <a href="CCMixtbl.html#TYPEsequence">sequence</a></code></pre><div class="info ">
Iterate on all bindings<br>
</div>
</body></html>