Package index
containers-data
Library containers-data
CCBV
Module
Imperative Bitvectors.
A bitvector is stored in some form of internal array (on the heap). Is it a bit similar to a more storage-efficient version of bool CCVector.vector, with additional operations.
BREAKING CHANGES since 1.2: size is now stored along with the bitvector. Some functions have a new signature.
The size of the bitvector used to be rounded up to the multiple of 30 or 62. In other words some functions such as iter would iterate on more bits than what was originally asked for. This is not the case anymore.
Empty bitvector. Length is 0.
Source val create : size :int -> bool -> t Create a bitvector of given size, with given default value. Length of result is size.
Source val init : int -> (int -> bool) -> t init len f initializes a bitvector of length len, where bit i is true iff f i is.
Number of bits set to one, seen as a set of bits.
Size of underlying bitvector. This is not related to the underlying implementation. Changed at 1.2
The number of bits this bitvector can store without resizing.
Source val resize : t -> int -> unitResize the BV so that it has the specified length. This can grow the underlying array, but it will not shrink it, to minimize memory traffic.
Source val resize_minimize_memory : t -> int -> unitSame as resize , but this can also shrink the underlying array if this reduces the size.
Set i-th bit, extending the bitvector if needed.
Is the i-th bit true? Return false if the index is too high.
Set i-th bit to 0, extending the bitvector if needed.
Source val set_bool : t -> int -> bool -> unitFlip i-th bit, extending the bitvector if needed.
Set every bit to 0. Does not change the length.
Source val clear_and_shrink : t -> unitSet every bit to 0, and set length to 0.
Source val iter : t -> (int -> bool -> unit) -> unitSource val iter_true : t -> (int -> unit) -> unitIterate on bits set to 1.
List of indexes that are true.
Source val to_sorted_list : t -> int list Same as to_list , but also guarantees the list is sorted in increasing order.
From a list of true bits.
The bits are interpreted as indices into the returned bitvector, so the final bitvector bv will have length bv equal to 1 more than max of list indices.
First set bit, or return None. Changed type at 1.2
Source val filter : t -> (int -> bool) -> unitfilter bv p only keeps the true bits of bv whose index satisfies p index. Length is unchanged.
negate_self t flips all of the bits in t. Length is unchanged.
negate t returns a copy of t with all of the bits flipped. Length is unchanged.
Source val union_into : into :t -> t -> unitunion_into ~into bv sets into to the union of itself and bv. Also updates the length of into to be at least length bv.
Source val inter_into : into :t -> t -> unitinter_into ~into bv sets into to the intersection of itself and bv. Also updates the length of into to be at most length bv.
After executing:
length ~into' = min (length into) (length bv).for all i: get into' ==> get into i /\ get bv iunion bv1 bv2 returns the union of the two sets. The length of the result is the max of the inputs' lengths.
inter bv1 bv2 returns the intersection of the two sets. The length of the result is the min of the inputs' lengths.
Source val diff_into : into :t -> t -> unitdiff_into ~into t modifies into with only the bits set but not in t.
diff t1 t2 returns those bits found in t1 but not in t2.
Source val select : t -> 'a array -> 'a listselect arr bv selects the elements of arr whose index corresponds to a true bit in bv. If bv is too short, elements of arr with too high an index cannot be selected and are therefore not selected.
Source val selecti : t -> 'a array -> ('a * int) listSame as select , but selected elements are paired with their indexes.
Bitwise comparison, including the size (equal a b implies length a=length b).
Source type 'a iter = ('a -> unit) -> unit Iterate over the true bits.
Print the bitvector as a string of bits.