ocaml-containers/1.4/CCRAL.html
2017-12-24 16:48:20 +01:00

278 lines
No EOL
20 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="CCWBTree.html">
<link rel="next" href="CCSimple_queue.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="Utils" rel="Section" href="#2_Utils">
<link title="Conversions" rel="Section" href="#2_Conversions">
<link title="Infix" rel="Section" href="#2_Infix">
<link title="IO" rel="Section" href="#2_IO">
<title>Containers doc : CCRAL</title>
</head>
<body>
<div class="navbar"><a class="pre" href="CCWBTree.html" title="CCWBTree">Previous</a>
&nbsp;<a class="up" href="index.html" title="Index">Up</a>
&nbsp;<a class="post" href="CCSimple_queue.html" title="CCSimple_queue">Next</a>
</div>
<h1>Module <a href="type_CCRAL.html">CCRAL</a></h1>
<pre><span class="keyword">module</span> CCRAL: <code class="code"><span class="keyword">sig</span></code> <a href="CCRAL.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<h1 id="1_RandomAccessLists">Random-Access Lists</h1>
<p>
This is an OCaml implementation of Okasaki's paper
"Purely Functional Random Access Lists". It defines a list-like data
structure with O(1) cons/tail operations, and O(log(n)) lookup/modification
operations.
<p>
This module used to be part of <code class="code">containers.misc</code>
<p>
<b>status: stable</b><br>
<b>Since</b> 0.13<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 ">
List containing elements of type 'a<br>
</div>
<pre><span id="VALempty"><span class="keyword">val</span> empty</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Empty list<br>
</div>
<pre><span id="VALis_empty"><span class="keyword">val</span> is_empty</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> bool</code></pre><div class="info ">
Check whether the list is empty<br>
</div>
<pre><span id="VALcons"><span class="keyword">val</span> cons</span> : <code class="type">'a -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Add an element at the front of the list<br>
</div>
<pre><span id="VALreturn"><span class="keyword">val</span> return</span> : <code class="type">'a -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Singleton<br>
</div>
<pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">f:('a -> 'b) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'b <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Map on elements<br>
</div>
<pre><span id="VALmapi"><span class="keyword">val</span> mapi</span> : <code class="type">f:(int -> 'a -> 'b) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'b <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Map with index<br>
</div>
<pre><span id="VALhd"><span class="keyword">val</span> hd</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a</code></pre><div class="info ">
First element of the list, or<br>
<b>Raises</b> <code>Invalid_argument</code> if the list is empty<br>
</div>
<pre><span id="VALtl"><span class="keyword">val</span> tl</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Remove the first element from the list, or<br>
<b>Raises</b> <code>Invalid_argument</code> if the list is empty<br>
</div>
<pre><span id="VALfront"><span class="keyword">val</span> front</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> ('a * 'a <a href="CCRAL.html#TYPEt">t</a>) option</code></pre><div class="info ">
Remove and return the first element of the list<br>
</div>
<pre><span id="VALfront_exn"><span class="keyword">val</span> front_exn</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a * 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Unsafe version of <a href="CCRAL.html#VALfront"><code class="code"><span class="constructor">CCRAL</span>.front</code></a>.<br>
<b>Raises</b> <code>Invalid_argument</code> if the list is empty<br>
</div>
<pre><span id="VALlength"><span class="keyword">val</span> length</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> int</code></pre><div class="info ">
Number of elements. Complexity O(ln n) where n=number of elements<br>
</div>
<pre><span id="VALget"><span class="keyword">val</span> get</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> int -> 'a option</code></pre><div class="info ">
<code class="code">get&nbsp;l&nbsp;i</code> accesses the <code class="code">i</code>-th element of the list. O(log(n)).<br>
</div>
<pre><span id="VALget_exn"><span class="keyword">val</span> get_exn</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> int -> 'a</code></pre><div class="info ">
Unsafe version of <a href="CCRAL.html#VALget"><code class="code"><span class="constructor">CCRAL</span>.get</code></a><br>
<b>Raises</b> <code>Invalid_argument</code> if the list has less than <code class="code">i+1</code> elements.<br>
</div>
<pre><span id="VALset"><span class="keyword">val</span> set</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> int -> 'a -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">set&nbsp;l&nbsp;i&nbsp;v</code> sets the <code class="code">i</code>-th element of the list to <code class="code">v</code>. O(log(n)).<br>
<b>Raises</b> <code>Invalid_argument</code> if the list has less than <code class="code">i+1</code> elements.<br>
</div>
<pre><span id="VALremove"><span class="keyword">val</span> remove</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> int -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">remove&nbsp;l&nbsp;i</code> removes the <code class="code">i</code>-th element of <code class="code">v</code>.<br>
<b>Raises</b> <code>Invalid_argument</code> if the list has less than <code class="code">i+1</code> elements.<br>
</div>
<pre><span id="VALappend"><span class="keyword">val</span> append</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALfilter"><span class="keyword">val</span> filter</span> : <code class="type">f:('a -> bool) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALfilter_map"><span class="keyword">val</span> filter_map</span> : <code class="type">f:('a -> 'b option) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'b <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALflat_map"><span class="keyword">val</span> flat_map</span> : <code class="type">('a -> 'b <a href="CCRAL.html#TYPEt">t</a>) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'b <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALflatten"><span class="keyword">val</span> flatten</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALapp"><span class="keyword">val</span> app</span> : <code class="type">('a -> 'b) <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'b <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALtake"><span class="keyword">val</span> take</span> : <code class="type">int -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALtake_while"><span class="keyword">val</span> take_while</span> : <code class="type">f:('a -> bool) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALdrop"><span class="keyword">val</span> drop</span> : <code class="type">int -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALdrop_while"><span class="keyword">val</span> drop_while</span> : <code class="type">f:('a -> bool) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALtake_drop"><span class="keyword">val</span> take_drop</span> : <code class="type">int -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a> * 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">take_drop&nbsp;n&nbsp;l</code> splits <code class="code">l</code> into <code class="code">a,&nbsp;b</code> such that <code class="code">length&nbsp;a&nbsp;=&nbsp;n</code>
if <code class="code">length&nbsp;l&nbsp;&gt;=&nbsp;n</code>, and such that <code class="code">append&nbsp;a&nbsp;b&nbsp;=&nbsp;l</code><br>
</div>
<pre><span id="VALiter"><span class="keyword">val</span> iter</span> : <code class="type">f:('a -> unit) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> unit</code></pre><div class="info ">
Iterate on the list's elements<br>
</div>
<pre><span id="VALiteri"><span class="keyword">val</span> iteri</span> : <code class="type">f:(int -> 'a -> unit) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> unit</code></pre>
<pre><span id="VALfold"><span class="keyword">val</span> fold</span> : <code class="type">f:('b -> 'a -> 'b) -> x:'b -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'b</code></pre><div class="info ">
Fold on the list's elements<br>
</div>
<pre><span id="VALfold_rev"><span class="keyword">val</span> fold_rev</span> : <code class="type">f:('b -> 'a -> 'b) -> x:'b -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'b</code></pre><div class="info ">
Fold on the list's elements, in reverse order (starting from the tail)<br>
</div>
<pre><span id="VALrev_map"><span class="keyword">val</span> rev_map</span> : <code class="type">f:('a -> 'b) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'b <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">rev_map&nbsp;f&nbsp;l</code> is the same as <code class="code">map&nbsp;f&nbsp;(rev&nbsp;l)</code><br>
</div>
<pre><span id="VALrev"><span class="keyword">val</span> rev</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Reverse the list<br>
</div>
<pre><span id="VALequal"><span class="keyword">val</span> equal</span> : <code class="type">?eq:('a -> 'a -> bool) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a> -> bool</code></pre>
<pre><span id="VALcompare"><span class="keyword">val</span> compare</span> : <code class="type">?cmp:('a -> 'a -> int) -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a> -> int</code></pre><div class="info ">
Lexicographic comparison<br>
</div>
<br>
<h2 id="2_Utils">Utils</h2><br>
<pre><span id="VALmake"><span class="keyword">val</span> make</span> : <code class="type">int -> 'a -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALrepeat"><span class="keyword">val</span> repeat</span> : <code class="type">int -> 'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">repeat&nbsp;n&nbsp;l</code> is <code class="code">append&nbsp;l&nbsp;(append&nbsp;l&nbsp;...&nbsp;l)</code> <code class="code">n</code> times<br>
</div>
<pre><span id="VALrange"><span class="keyword">val</span> range</span> : <code class="type">int -> int -> int <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
<code class="code">range&nbsp;i&nbsp;j</code> is <code class="code">i;&nbsp;i+1;&nbsp;...&nbsp;;&nbsp;j</code> or <code class="code">j;&nbsp;j-1;&nbsp;...;&nbsp;i</code><br>
</div>
<br>
<h2 id="2_Conversions">Conversions</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="TYPEgen"><span class="keyword">type</span> <code class="type">'a</code> gen</span> = <code class="type">unit -> 'a option</code> </pre>
<pre><span id="VALadd_list"><span class="keyword">val</span> add_list</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a list -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALof_list"><span class="keyword">val</span> of_list</span> : <code class="type">'a list -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Convert a list to a RAL. <b>Caution</b>: non tail-rec<br>
</div>
<pre><span id="VALto_list"><span class="keyword">val</span> to_list</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a list</code></pre>
<pre><span id="VALof_list_map"><span class="keyword">val</span> of_list_map</span> : <code class="type">f:('a -> 'b) -> 'a list -> 'b <a href="CCRAL.html#TYPEt">t</a></code></pre><div class="info ">
Combination of <a href="CCRAL.html#VALof_list"><code class="code"><span class="constructor">CCRAL</span>.of_list</code></a> and <a href="CCRAL.html#VALmap"><code class="code"><span class="constructor">CCRAL</span>.map</code></a><br>
</div>
<pre><span id="VALof_array"><span class="keyword">val</span> of_array</span> : <code class="type">'a array -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALadd_array"><span class="keyword">val</span> add_array</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a array -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALto_array"><span class="keyword">val</span> to_array</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a array</code></pre><div class="info ">
More efficient than on usual lists<br>
</div>
<pre><span id="VALadd_seq"><span class="keyword">val</span> add_seq</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEsequence">sequence</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALof_seq"><span class="keyword">val</span> of_seq</span> : <code class="type">'a <a href="CCRAL.html#TYPEsequence">sequence</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALto_seq"><span class="keyword">val</span> to_seq</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEsequence">sequence</a></code></pre>
<pre><span id="VALadd_gen"><span class="keyword">val</span> add_gen</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEgen">gen</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALof_gen"><span class="keyword">val</span> of_gen</span> : <code class="type">'a <a href="CCRAL.html#TYPEgen">gen</a> -> 'a <a href="CCRAL.html#TYPEt">t</a></code></pre>
<pre><span id="VALto_gen"><span class="keyword">val</span> to_gen</span> : <code class="type">'a <a href="CCRAL.html#TYPEt">t</a> -> 'a <a href="CCRAL.html#TYPEgen">gen</a></code></pre><br>
<h2 id="2_Infix">Infix</h2><br>
<pre><span class="keyword">module</span> <a href="CCRAL.Infix.html">Infix</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCRAL.Infix.html">..</a> <code class="code"><span class="keyword">end</span></code></pre>
<pre><span class="keyword">include</span> <a href="CCRAL.Infix.html">CCRAL.Infix</a></pre>
<br>
<h2 id="2_IO">IO</h2><br>
<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>
<pre><span id="VALprint"><span class="keyword">val</span> print</span> : <code class="type">?sep:string -> 'a <a href="CCRAL.html#TYPEprinter">printer</a> -> 'a <a href="CCRAL.html#TYPEt">t</a> <a href="CCRAL.html#TYPEprinter">printer</a></code></pre></body></html>