Module CCBV
Imperative Bitvectors
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.
val empty : unit -> tEmpty bitvector.
val create : size:int -> bool -> tCreate a bitvector of given size, with given default value.
val cardinal : t -> intNumber of bits set to one, seen as a set of bits.
val length : t -> intSize of underlying bitvector. This is not related to the underlying implementation. Changed at 1.2
val capacity : t -> intThe number of bits this bitvector can store without resizing.
- since
- 1.2
val resize : t -> int -> unitResize the BV so that it has the specified length. This can grow or shrink the underlying bitvector.
- raises Invalid_arg
on negative sizes.
val is_empty : t -> boolAre there any true bits?
val set : t -> int -> unitSet i-th bit, extending the bitvector if needed.
val get : t -> int -> boolIs the i-th bit true? Return false if the index is too high.
val reset : t -> int -> unitSet i-th bit to 0, extending the bitvector if needed.
val flip : t -> int -> unitFlip i-th bit, extending the bitvector if needed.
val clear : t -> unitSet every bit to 0.
val iter : t -> (int -> bool -> unit) -> unitIterate on all bits.
val iter_true : t -> (int -> unit) -> unitIterate on bits set to 1.
val to_list : t -> int listList of indexes that are true.
val to_sorted_list : t -> int listSame as
to_list, but also guarantees the list is sorted in increasing order.
val of_list : int list -> tFrom a list of true bits.
The bits are interpreted as indices into the returned bitvector, so the final bitvector will have
length tequal to 1 more than max of list indices.
val first : t -> int optionFirst set bit, or return
None. Changed type at 1.2
val first_exn : t -> intFirst set bit, or
- raises Not_found
if all bits are 0.
- since
- 1.2
val filter : t -> (int -> bool) -> unitfilter bv ponly keeps the true bits ofbvwhoseindexsatisfiesp index.
val negate_self : t -> unitnegate_self tflips all of the bits int.- since
- 1.2
val union_into : into:t -> t -> unitunion_into ~into bvsetsintoto the union of itself andbv. Also updates the length ofintoto be at leastlength bv.
val inter_into : into:t -> t -> unitinter_into ~into bvsetsintoto the intersection of itself andbv. Also updates the length ofintoto be at mostlength bv.
val diff_into : into:t -> t -> unitdiff_into ~into tmodifiesintowith only the bits set but not int.- since
- 1.2
val select : t -> 'a array -> 'a listselect arr bvselects the elements ofarrwhose index corresponds to a true bit inbv. Ifbvis too short, elements ofarrwith too high an index cannot be selected and are therefore not selected.