mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
2 lines
No EOL
13 KiB
HTML
2 lines
No EOL
13 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>CCBV (containers.CCBV)</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> » CCBV</nav><h1>Module <code>CCBV</code></h1><h2 id="imperative-bitvectors"><a href="#imperative-bitvectors" class="anchor"></a>Imperative Bitvectors</h2><p><b>BREAKING CHANGES</b> since 1.2: size is now stored along with the bitvector. Some functions have a new signature.</p><p>The size of the bitvector used to be rounded up to the multiple of 30 or 62. In other words some functions such as <a href="index.html#val-iter"><code>iter</code></a> would iterate on more bits than what was originally asked for. This is not the case anymore.</p></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type </span>t</code></dt><dd><p>A resizable bitvector</p></dd></dl><dl><dt class="spec value" id="val-empty"><a href="#val-empty" class="anchor"></a><code><span class="keyword">val </span>empty : unit <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p>Empty bitvector.</p></dd></dl><dl><dt class="spec value" id="val-create"><a href="#val-create" class="anchor"></a><code><span class="keyword">val </span>create : size:int <span>-></span> bool <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p>Create a bitvector of given size, with given default value.</p></dd></dl><dl><dt class="spec value" id="val-copy"><a href="#val-copy" class="anchor"></a><code><span class="keyword">val </span>copy : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p>Copy of bitvector.</p></dd></dl><dl><dt class="spec value" id="val-cardinal"><a href="#val-cardinal" class="anchor"></a><code><span class="keyword">val </span>cardinal : <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p>Number of bits set to one, seen as a set of bits.</p></dd></dl><dl><dt class="spec value" id="val-length"><a href="#val-length" class="anchor"></a><code><span class="keyword">val </span>length : <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p>Size of underlying bitvector. This is not related to the underlying implementation. Changed at 1.2</p></dd></dl><dl><dt class="spec value" id="val-capacity"><a href="#val-capacity" class="anchor"></a><code><span class="keyword">val </span>capacity : <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p>The number of bits this bitvector can store without resizing.</p><dl><dt>since</dt><dd>1.2</dd></dl></dd></dl><dl><dt class="spec value" id="val-resize"><a href="#val-resize" class="anchor"></a><code><span class="keyword">val </span>resize : <a href="index.html#type-t">t</a> <span>-></span> int <span>-></span> unit</code></dt><dd><p>Resize the BV so that it has the specified length. This can grow or shrink the underlying bitvector.</p><dl><dt>raises Invalid_arg</dt><dd><p>on negative sizes.</p></dd></dl></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>Are there any true bits?</p></dd></dl><dl><dt class="spec value" id="val-set"><a href="#val-set" class="anchor"></a><code><span class="keyword">val </span>set : <a href="index.html#type-t">t</a> <span>-></span> int <span>-></span> unit</code></dt><dd><p>Set i-th bit, extending the bitvector if needed.</p></dd></dl><dl><dt class="spec value" id="val-get"><a href="#val-get" class="anchor"></a><code><span class="keyword">val </span>get : <a href="index.html#type-t">t</a> <span>-></span> int <span>-></span> bool</code></dt><dd><p>Is the i-th bit true? Return false if the index is too high.</p></dd></dl><dl><dt class="spec value" id="val-reset"><a href="#val-reset" class="anchor"></a><code><span class="keyword">val </span>reset : <a href="index.html#type-t">t</a> <span>-></span> int <span>-></span> unit</code></dt><dd><p>Set i-th bit to 0, extending the bitvector if needed.</p></dd></dl><dl><dt class="spec value" id="val-flip"><a href="#val-flip" class="anchor"></a><code><span class="keyword">val </span>flip : <a href="index.html#type-t">t</a> <span>-></span> int <span>-></span> unit</code></dt><dd><p>Flip i-th bit, extending the bitvector if needed.</p></dd></dl><dl><dt class="spec value" id="val-clear"><a href="#val-clear" class="anchor"></a><code><span class="keyword">val </span>clear : <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p>Set every bit to 0.</p></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-t">t</a> <span>-></span> (int <span>-></span> bool <span>-></span> unit) <span>-></span> unit</code></dt><dd><p>Iterate on all bits.</p></dd></dl><dl><dt class="spec value" id="val-iter_true"><a href="#val-iter_true" class="anchor"></a><code><span class="keyword">val </span>iter_true : <a href="index.html#type-t">t</a> <span>-></span> (int <span>-></span> unit) <span>-></span> unit</code></dt><dd><p>Iterate on bits set to 1.</p></dd></dl><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> int list</code></dt><dd><p>List of indexes that are true.</p></dd></dl><dl><dt class="spec value" id="val-to_sorted_list"><a href="#val-to_sorted_list" class="anchor"></a><code><span class="keyword">val </span>to_sorted_list : <a href="index.html#type-t">t</a> <span>-></span> int list</code></dt><dd><p>Same as <a href="index.html#val-to_list"><code>to_list</code></a>, but also guarantees the list is sorted in increasing order.</p></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 : int list <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p>From a list of true bits.</p><p>The bits are interpreted as indices into the returned bitvector, so the final bitvector will have <code>length t</code> equal to 1 more than max of list indices.</p></dd></dl><dl><dt class="spec value" id="val-first"><a href="#val-first" class="anchor"></a><code><span class="keyword">val </span>first : <a href="index.html#type-t">t</a> <span>-></span> int option</code></dt><dd><p>First set bit, or return <code>None</code>. Changed type at 1.2</p></dd></dl><dl><dt class="spec value" id="val-first_exn"><a href="#val-first_exn" class="anchor"></a><code><span class="keyword">val </span>first_exn : <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p>First set bit, or</p><dl><dt>raises Not_found</dt><dd><p>if all bits are 0.</p></dd></dl><dl><dt>since</dt><dd>1.2</dd></dl></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-t">t</a> <span>-></span> (int <span>-></span> bool) <span>-></span> unit</code></dt><dd><p><code>filter bv p</code> only keeps the true bits of <code>bv</code> whose <code>index</code> satisfies <code>p index</code>.</p></dd></dl><dl><dt class="spec value" id="val-negate_self"><a href="#val-negate_self" class="anchor"></a><code><span class="keyword">val </span>negate_self : <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p><code>negate_self t</code> flips all of the bits in <code>t</code>.</p><dl><dt>since</dt><dd>1.2</dd></dl></dd></dl><dl><dt class="spec value" id="val-negate"><a href="#val-negate" class="anchor"></a><code><span class="keyword">val </span>negate : <a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>negate t</code> returns a copy of <code>t</code> with all of the bits flipped.</p></dd></dl><dl><dt class="spec value" id="val-union_into"><a href="#val-union_into" class="anchor"></a><code><span class="keyword">val </span>union_into : into:<a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p><code>union_into ~into bv</code> sets <code>into</code> to the union of itself and <code>bv</code>. Also updates the length of <code>into</code> to be at least <code>length bv</code>.</p></dd></dl><dl><dt class="spec value" id="val-inter_into"><a href="#val-inter_into" class="anchor"></a><code><span class="keyword">val </span>inter_into : into:<a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p><code>inter_into ~into bv</code> sets <code>into</code> to the intersection of itself and <code>bv</code>. Also updates the length of <code>into</code> to be at most <code>length bv</code>.</p></dd></dl><dl><dt class="spec value" id="val-union"><a href="#val-union" class="anchor"></a><code><span class="keyword">val </span>union : <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>union bv1 bv2</code> returns the union of the two sets.</p></dd></dl><dl><dt class="spec value" id="val-inter"><a href="#val-inter" class="anchor"></a><code><span class="keyword">val </span>inter : <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>inter bv1 bv2</code> returns the intersection of the two sets.</p></dd></dl><dl><dt class="spec value" id="val-diff_into"><a href="#val-diff_into" class="anchor"></a><code><span class="keyword">val </span>diff_into : into:<a href="index.html#type-t">t</a> <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p><code>diff_into ~into t</code> modifies <code>into</code> with only the bits set but not in <code>t</code>.</p><dl><dt>since</dt><dd>1.2</dd></dl></dd></dl><dl><dt class="spec value" id="val-diff"><a href="#val-diff" class="anchor"></a><code><span class="keyword">val </span>diff : <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>diff t1 t2</code> returns those bits found in <code>t1</code> but not in <code>t2</code>.</p><dl><dt>since</dt><dd>1.2</dd></dl></dd></dl><dl><dt class="spec value" id="val-select"><a href="#val-select" class="anchor"></a><code><span class="keyword">val </span>select : <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span> array <span>-></span> <span class="type-var">'a</span> list</code></dt><dd><p><code>select arr bv</code> selects the elements of <code>arr</code> whose index corresponds to a true bit in <code>bv</code>. If <code>bv</code> is too short, elements of <code>arr</code> with too high an index cannot be selected and are therefore not selected.</p></dd></dl><dl><dt class="spec value" id="val-selecti"><a href="#val-selecti" class="anchor"></a><code><span class="keyword">val </span>selecti : <a href="index.html#type-t">t</a> <span>-></span> <span class="type-var">'a</span> array <span>-></span> (<span class="type-var">'a</span><span class="keyword"> * </span>int) list</code></dt><dd><p>Same as <a href="index.html#val-select"><code>select</code></a>, but selected elements are paired with their indexes.</p></dd></dl><dl><dt class="spec type" id="type-sequence"><a href="#type-sequence" class="anchor"></a><code><span class="keyword">type </span>'a sequence</code><code><span class="keyword"> = </span>(<span class="type-var">'a</span> <span>-></span> unit) <span>-></span> unit</code></dt></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> int <a href="index.html#type-sequence">sequence</a></code></dt><dt class="spec value" id="val-of_seq"><a href="#val-of_seq" class="anchor"></a><code><span class="keyword">val </span>of_seq : int <a href="index.html#type-sequence">sequence</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-pp"><a href="#val-pp" class="anchor"></a><code><span class="keyword">val </span>pp : Format.formatter <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p>Print the bitvector as a string of bits.</p><dl><dt>since</dt><dd>0.13</dd></dl></dd></dl></div></body></html> |