Legend:
Library
Module
Module type
Parameter
Class
Class type
This module implements bit vectors, as an abstract datatype t. Since bit vectors are particular cases of arrays, this module provides the same operations as module Array. It also provides bitwise operations and conversions to/from integer types.
In the following, false stands for bit 0 and true for bit 1.
Bitv.tanimoto v1 v2 is |inter(v1,v2)| / |union(v1,v2)|. Also called the Jaccard score. (1 - tanimoto) is a proper distance. raises Invalid_argument if the two vectors do not have the same length
val max_length : int
deprecated
Use exceeds_max_length instead. On a 32-bit platform (e.g. Javascript) the computation of max_length may overflow and return a negative value.
val exceeds_max_length : int -> bool
Returns true if the argument exceeds the maximum length of a bit vector (System dependent).
(Bitv.sub v start len) returns a fresh vector of length len, containing the bits number start to start + len - 1 of vector v. Raise Invalid_argument
"Bitv.sub" if start and len do not designate a valid subvector of v; that is, if start < 0, or len < 0, or start
+ len > Bitv.length a.
(Bitv.fill v ofs len b) modifies the vector v in place, storing b in elements number ofs to ofs + len - 1. Raise Invalid_argument "Bitv.fill" if ofs and len do not designate a valid subvector of v.
(Bitv.blit v1 o1 v2 o2 len) copies len elements from vector v1, starting at element number o1, to vector v2, starting at element number o2. It does not work correctly if v1 and v2 are the same vector with the source and destination chunks overlapping. Raise Invalid_argument "Bitv.blit" if o1 and len do not designate a valid subvector of v1, or if o2 and len do not designate a valid subvector of v2.
Bitv.iteri and Bitv.mapi are similar to Bitv.iter and Bitv.map respectively, but the function is applied to the index of the element as first argument, and the element itself as second argument.
iteri_true f v applies function f in turn to all indexes of the elements of v which are set (i.e. true); indexes are visited from least significant to most significant.
gray_iter f n iterates function f on all bit vectors of length n, once each, using a Gray code. The order in which bit vectors are processed is unspecified.
The following functions export/import a bit vector to/from a channel or bytes, in a way that is compact, independent of the machine architecture, and independent of the OCaml version. For a bit vector of length n, the number of bytes of this external representation is 8+ceil(n/8).
Least significant bit comes first (ie is at index 0 in the bit vector). to_xxx functions truncate when the bit vector is too wide. Suffix _s means that sign bit is kept, and _us that it is discarded.