mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
2 lines
No EOL
17 KiB
HTML
2 lines
No EOL
17 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Make_from_compare (containers.CCHeap.Make_from_compare)</title><link rel="stylesheet" href="../../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> – <a href="../../index.html">containers</a> » <a href="../index.html">CCHeap</a> » Make_from_compare</nav><h1>Module <code>CCHeap.Make_from_compare</code></h1><p>A convenient version of <code>Make</code> that take a <code>TOTAL_ORD</code> instead of a partially ordered module. It allow to directly pass modules that implement <code>compare</code> without implementing <code>leq</code> explicitly</p><nav class="toc"><ul><li><a href="#conversions">Conversions</a></li></ul></nav></header><h3 class="heading">Parameters</h3><ul><li><code><a href="argument-1-E/index.html">E</a> : <a href="../index.html#module-type-TOTAL_ORD">TOTAL_ORD</a></code></li></ul><h3 class="heading">Signature</h3><dl><dt class="spec type" id="type-elt"><a href="#type-elt" class="anchor"></a><code><span class="keyword">type</span> elt</code><code> = <a href="argument-1-E/index.html#type-t">E.t</a></code></dt><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> t</code></dt></dl><dl><dt class="spec value" id="val-empty"><a href="#val-empty" class="anchor"></a><code><span class="keyword">val</span> empty : <a href="index.html#type-t">t</a></code></dt><dd><p><code>empty</code> returns the empty heap.</p></dd></dl><dl><dt class="spec value" id="val-is_empty"><a href="#val-is_empty" class="anchor"></a><code><span class="keyword">val</span> is_empty : <a href="index.html#type-t">t</a> <span>-></span> bool</code></dt><dd><p><code>is_empty h</code> returns <code>true</code> if the heap <code>h</code> is empty.</p></dd></dl><dl><dt class="spec exception" id="exception-Empty"><a href="#exception-Empty" class="anchor"></a><code><span class="keyword">exception</span> </code><code><span class="exception">Empty</span></code></dt></dl><dl><dt class="spec value" id="val-merge"><a href="#val-merge" class="anchor"></a><code><span class="keyword">val</span> merge : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>merge h1 h2</code> merges the two heaps <code>h1</code> and <code>h2</code>.</p></dd></dl><dl><dt class="spec value" id="val-insert"><a href="#val-insert" class="anchor"></a><code><span class="keyword">val</span> insert : <a href="index.html#type-elt">elt</a> <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>insert x h</code> inserts an element <code>x</code> into the heap <code>h</code>.</p></dd></dl><dl><dt class="spec value" id="val-add"><a href="#val-add" class="anchor"></a><code><span class="keyword">val</span> add : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>add h x</code> inserts an element <code>x</code> into the heap <code>h</code>.</p></dd></dl><dl><dt class="spec value" id="val-filter"><a href="#val-filter" class="anchor"></a><code><span class="keyword">val</span> filter : (<a href="index.html#type-elt">elt</a> <span>-></span> bool) <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>filter p h</code> filters values, only retaining the ones that satisfy the predicate <code>p</code>. Linear time at least.</p></dd></dl><dl><dt class="spec value" id="val-find_min"><a href="#val-find_min" class="anchor"></a><code><span class="keyword">val</span> find_min : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> option</code></dt><dd><p><code>find_min h</code> find the minimal element of the heap <code>h</code>.</p></dd></dl><dl><dt class="spec value" id="val-find_min_exn"><a href="#val-find_min_exn" class="anchor"></a><code><span class="keyword">val</span> find_min_exn : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a></code></dt><dd><p><code>find_min_exn h</code> is like <a href="index.html#val-find_min"><code>find_min</code></a> but can fail.</p><dl><dt>raises Empty</dt><dd><p>if the heap is empty.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-take"><a href="#val-take" class="anchor"></a><code><span class="keyword">val</span> take : <a href="index.html#type-t">t</a> <span>-></span> (<a href="index.html#type-t">t</a> * <a href="index.html#type-elt">elt</a>) option</code></dt><dd><p><code>take h</code> extracts and returns the minimum element, and the new heap (without this element), or <code>None</code> if the heap <code>h</code> is empty.</p></dd></dl><dl><dt class="spec value" id="val-take_exn"><a href="#val-take_exn" class="anchor"></a><code><span class="keyword">val</span> take_exn : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a> * <a href="index.html#type-elt">elt</a></code></dt><dd><p><code>take_exn h</code> is like <a href="index.html#val-take"><code>take</code></a>, but can fail.</p><dl><dt>raises Empty</dt><dd><p>if the heap is empty.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-delete_one"><a href="#val-delete_one" class="anchor"></a><code><span class="keyword">val</span> delete_one : (<a href="index.html#type-elt">elt</a> <span>-></span> <a href="index.html#type-elt">elt</a> <span>-></span> bool) <span>-></span> <a href="index.html#type-elt">elt</a> <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>delete_one eq x h</code> uses <code>eq</code> to find one occurrence of a value <code>x</code> if it exist in the heap <code>h</code>, and delete it. If <code>h</code> do not contain <code>x</code> then it return <code>h</code>.</p><dl><dt>since</dt><dd>2.0</dd></dl></dd></dl><dl><dt class="spec value" id="val-delete_all"><a href="#val-delete_all" class="anchor"></a><code><span class="keyword">val</span> delete_all : (<a href="index.html#type-elt">elt</a> <span>-></span> <a href="index.html#type-elt">elt</a> <span>-></span> bool) <span>-></span> <a href="index.html#type-elt">elt</a> <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>delete_all eq x h</code> uses <code>eq</code> to find all <code>x</code> in <code>h</code> and delete them. If <code>h</code> do not contain <code>x</code> then it return <code>h</code>. The difference with <a href="index.html#val-filter"><code>filter</code></a> is that <code>delete_all</code> stops as soon as it enters a subtree whose root is bigger than the element.</p><dl><dt>since</dt><dd>2.0</dd></dl></dd></dl><dl><dt class="spec value" id="val-iter"><a href="#val-iter" class="anchor"></a><code><span class="keyword">val</span> iter : (<a href="index.html#type-elt">elt</a> <span>-></span> unit) <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p><code>iter f h</code> iterates over the heap <code>h</code> invoking <code>f</code> with the current element.</p></dd></dl><dl><dt class="spec value" id="val-fold"><a href="#val-fold" class="anchor"></a><code><span class="keyword">val</span> fold : (<span class="type-var">'a</span> <span>-></span> <a href="index.html#type-elt">elt</a> <span>-></span> <span class="type-var">'a</span>) <span>-></span> <span class="type-var">'a</span> <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span></code></dt><dd><p><code>fold f acc h</code> folds on all values of <code>h</code>.</p></dd></dl><dl><dt class="spec value" id="val-size"><a href="#val-size" class="anchor"></a><code><span class="keyword">val</span> size : <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p><code>size h</code> is the number of elements in the heap <code>h</code>. Linear complexity.</p></dd></dl><section><header><h3 id="conversions"><a href="#conversions" class="anchor"></a>Conversions</h3></header><dl><dt class="spec value" id="val-to_list"><a href="#val-to_list" class="anchor"></a><code><span class="keyword">val</span> to_list : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> list</code></dt><dd><p><code>to_list h</code> returns the elements of the heap <code>h</code>, in no particular order.</p></dd></dl><dl><dt class="spec value" id="val-to_list_sorted"><a href="#val-to_list_sorted" class="anchor"></a><code><span class="keyword">val</span> to_list_sorted : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> list</code></dt><dd><p><code>to_list_sorted h</code> returns the elements of the heap <code>h</code> in increasing order.</p><dl><dt>since</dt><dd>1.1</dd></dl></dd></dl><dl><dt class="spec value" id="val-add_list"><a href="#val-add_list" class="anchor"></a><code><span class="keyword">val</span> add_list : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> list <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>add_list h l</code> adds the elements of the list <code>l</code> into the heap <code>h</code>. An element occurring several times will be added that many times to the heap.</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl><dl><dt class="spec value" id="val-of_list"><a href="#val-of_list" class="anchor"></a><code><span class="keyword">val</span> of_list : <a href="index.html#type-elt">elt</a> list <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>of_list l</code> is <code>add_list empty l</code>. Complexity: <code>O(n log n)</code>.</p></dd></dl><dl><dt class="spec value" id="val-add_iter"><a href="#val-add_iter" class="anchor"></a><code><span class="keyword">val</span> add_iter : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> <a href="../index.html#type-iter">iter</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>add_iter h iter</code> is like <a href="index.html#val-add_list"><code>add_list</code></a>.</p><dl><dt>since</dt><dd>2.8</dd></dl></dd></dl><dl><dt class="spec value" id="val-add_seq"><a href="#val-add_seq" class="anchor"></a><code><span class="keyword">val</span> add_seq : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> Stdlib.Seq.t <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>add_seq h seq</code> is like <a href="index.html#val-add_list"><code>add_list</code></a>. Renamed from <code>add_std_seq</code> since 3.0.</p><dl><dt>since</dt><dd>3.0</dd></dl></dd></dl><dl><dt class="spec value" id="val-of_iter"><a href="#val-of_iter" class="anchor"></a><code><span class="keyword">val</span> of_iter : <a href="index.html#type-elt">elt</a> <a href="../index.html#type-iter">iter</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>of_iter iter</code> builds a heap from a given <code>iter</code>. Complexity: <code>O(n log n)</code>.</p><dl><dt>since</dt><dd>2.8</dd></dl></dd></dl><dl><dt class="spec value" id="val-of_seq"><a href="#val-of_seq" class="anchor"></a><code><span class="keyword">val</span> of_seq : <a href="index.html#type-elt">elt</a> Stdlib.Seq.t <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>of_seq seq</code> builds a heap from a given <code>Seq.t</code>. Complexity: <code>O(n log n)</code>. Renamed from <code>of_seq</code> since 3.0.</p><dl><dt>since</dt><dd>3.0</dd></dl></dd></dl><dl><dt class="spec value" id="val-to_iter"><a href="#val-to_iter" class="anchor"></a><code><span class="keyword">val</span> to_iter : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> <a href="../index.html#type-iter">iter</a></code></dt><dd><p><code>to_iter h</code> returns a <code>iter</code> of the elements of the heap <code>h</code>.</p><dl><dt>since</dt><dd>2.8</dd></dl></dd></dl><dl><dt class="spec value" id="val-to_seq"><a href="#val-to_seq" class="anchor"></a><code><span class="keyword">val</span> to_seq : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> Stdlib.Seq.t</code></dt><dd><p><code>to_seq h</code> returns a <code>Seq.t</code> of the elements of the heap <code>h</code>. Renamed from <code>to_std_seq</code> since 3.0.</p><dl><dt>since</dt><dd>3.0</dd></dl></dd></dl><dl><dt class="spec value" id="val-to_iter_sorted"><a href="#val-to_iter_sorted" class="anchor"></a><code><span class="keyword">val</span> to_iter_sorted : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> <a href="../index.html#type-iter">iter</a></code></dt><dd><p><code>to_iter_sorted h</code> returns a <code>iter</code> by iterating on the elements of <code>h</code>, in increasing order.</p><dl><dt>since</dt><dd>2.8</dd></dl></dd></dl><dl><dt class="spec value" id="val-to_seq_sorted"><a href="#val-to_seq_sorted" class="anchor"></a><code><span class="keyword">val</span> to_seq_sorted : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> Stdlib.Seq.t</code></dt><dd><p><code>to_seq_sorted h</code> returns a <code>Seq.t</code> by iterating on the elements of <code>h</code>, in increasing order. Renamed from <code>to_std_seq_sorted</code> since 3.0.</p><dl><dt>since</dt><dd>3.0</dd></dl></dd></dl><dl><dt class="spec value" id="val-add_gen"><a href="#val-add_gen" class="anchor"></a><code><span class="keyword">val</span> add_gen : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> <a href="../index.html#type-gen">gen</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>add_gen h gen</code> adds the gen <code>gen</code> to the heap <code>h</code>.</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl><dl><dt class="spec value" id="val-of_gen"><a href="#val-of_gen" class="anchor"></a><code><span class="keyword">val</span> of_gen : <a href="index.html#type-elt">elt</a> <a href="../index.html#type-gen">gen</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>of_gen gen</code> builds a heap from a given <code>gen</code>. Complexity: <code>O(n log n)</code>.</p></dd></dl><dl><dt class="spec value" id="val-to_gen"><a href="#val-to_gen" class="anchor"></a><code><span class="keyword">val</span> to_gen : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> <a href="../index.html#type-gen">gen</a></code></dt><dd><p><code>to_gen h</code> returns a <code>gen</code> of the elements of the heap <code>h</code>.</p></dd></dl><dl><dt class="spec value" id="val-to_tree"><a href="#val-to_tree" class="anchor"></a><code><span class="keyword">val</span> to_tree : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-elt">elt</a> <a href="../index.html#type-ktree">ktree</a></code></dt><dd><p><code>to_tree h</code> returns a <code>ktree</code> of the elements of the heap <code>h</code>.</p></dd></dl><dl><dt class="spec value" id="val-to_string"><a href="#val-to_string" class="anchor"></a><code><span class="keyword">val</span> to_string : ?⁠sep:string <span>-></span> (<a href="index.html#type-elt">elt</a> <span>-></span> string) <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> string</code></dt><dd><p><code>to_string ?sep f h</code> prints the heap <code>h</code> in a string using <code>sep</code> as a given separator (default ",") between each element (converted to a string using <code>f</code>).</p><dl><dt>since</dt><dd>2.7</dd></dl></dd></dl><dl><dt class="spec value" id="val-pp"><a href="#val-pp" class="anchor"></a><code><span class="keyword">val</span> pp : ?⁠pp_start:unit <a href="../index.html#type-printer">printer</a> <span>-></span> ?⁠pp_stop:unit <a href="../index.html#type-printer">printer</a> <span>-></span> ?⁠pp_sep:unit <a href="../index.html#type-printer">printer</a> <span>-></span> <a href="index.html#type-elt">elt</a> <a href="../index.html#type-printer">printer</a> <span>-></span> <a href="index.html#type-t">t</a> <a href="../index.html#type-printer">printer</a></code></dt><dd><p><code>pp ?pp_start ?pp_stop ?pp_sep ppf h</code> prints <code>h</code> on <code>ppf</code>. Each element is formatted with <code>ppf</code>, <code>pp_start</code> is called at the beginning, <code>pp_stop</code> is called at the end, <code>pp_sep</code> is called between each elements. By defaults <code>pp_start</code> and <code>pp_stop</code> does nothing and <code>pp_sep</code> defaults to (fun out -> Format.fprintf out ",@ "). Renamed from <code>print</code> since 2.0</p><dl><dt>since</dt><dd>0.16</dd></dl></dd></dl></section></div></body></html> |