package containers-data
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=92143ceb4785ae5f8a07f3ab4ab9f6f32d31ead0536e9be4fdb818dd3c677e58
sha512=5fa80189d0e177af2302b48e72b70299d51fc36ac2019e1cbf389ff6a7f4705b10089405b5a719b3e4845b0d1349a47a967f865dc2e4e3f0d5a0167ef6c31431
doc/containers-data/CCBV/index.html
Module CCBV
Source
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.
A resizable bitvector
Create a bitvector of given size, with given default value. Length of result is size
.
init len f
initializes a bitvector of length len
, where bit i
is true iff f i
is.
Size of underlying bitvector. This is not related to the underlying implementation. Changed at 1.2
Resize 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.
Same as resize
, but this can also shrink the underlying array if this reduces the size.
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.
filter bv p
only keeps the true bits of bv
whose index
satisfies p index
. Length is unchanged.
negate t
returns a copy of t
with all of the bits flipped. Length is unchanged.
union_into ~into bv
sets into
to the union of itself and bv
. Also updates the length of into
to be at least length bv
.
inter_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 i
union 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.
diff_into ~into t
modifies into
with only the bits set but not in t
.
select 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.
Same as select
, but selected elements are paired with their indexes.
Bitwise comparison, including the size (equal a b
implies length a=length b
).
Print the bitvector as a string of bits.