package containers

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module CCBVSource

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.

Sourcetype t

A resizable bitvector

Sourceval empty : unit -> t

Empty bitvector.

Sourceval create : size:int -> bool -> t

Create a bitvector of given size, with given default value.

Sourceval copy : t -> t

Copy of bitvector.

Sourceval cardinal : t -> int

Number of bits set to one, seen as a set of bits.

Sourceval length : t -> int

Size of underlying bitvector. This is not related to the underlying implementation. Changed at 1.2

Sourceval capacity : t -> int

The number of bits this bitvector can store without resizing.

  • since 1.2
Sourceval resize : t -> int -> unit

Resize the BV so that it has the specified length. This can grow or shrink the underlying bitvector.

  • raises Invalid_arg

    on negative sizes.

Sourceval is_empty : t -> bool

Are there any true bits?

Sourceval set : t -> int -> unit

Set i-th bit, extending the bitvector if needed.

Sourceval get : t -> int -> bool

Is the i-th bit true? Return false if the index is too high.

Sourceval reset : t -> int -> unit

Set i-th bit to 0, extending the bitvector if needed.

Sourceval flip : t -> int -> unit

Flip i-th bit, extending the bitvector if needed.

Sourceval clear : t -> unit

Set every bit to 0.

Sourceval iter : t -> (int -> bool -> unit) -> unit

Iterate on all bits.

Sourceval iter_true : t -> (int -> unit) -> unit

Iterate on bits set to 1.

Sourceval to_list : t -> int list

List of indexes that are true.

Sourceval to_sorted_list : t -> int list

Same as to_list, but also guarantees the list is sorted in increasing order.

Sourceval of_list : int list -> t

From a list of true bits.

The bits are interpreted as indices into the returned bitvector, so the final bitvector will have length t equal to 1 more than max of list indices.

Sourceval first : t -> int option

First set bit, or return None. Changed type at 1.2

Sourceval first_exn : t -> int

First set bit, or

  • since 1.2
Sourceval filter : t -> (int -> bool) -> unit

filter bv p only keeps the true bits of bv whose index satisfies p index.

Sourceval negate_self : t -> unit

negate_self t flips all of the bits in t.

  • since 1.2
Sourceval negate : t -> t

negate t returns a copy of t with all of the bits flipped.

Sourceval union_into : into:t -> t -> unit

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.

Sourceval inter_into : into:t -> t -> unit

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.

Sourceval union : t -> t -> t

union bv1 bv2 returns the union of the two sets.

Sourceval inter : t -> t -> t

inter bv1 bv2 returns the intersection of the two sets.

Sourceval diff_into : into:t -> t -> unit

diff_into ~into t modifies into with only the bits set but not in t.

  • since 1.2
Sourceval diff : t -> t -> t

diff t1 t2 returns those bits found in t1 but not in t2.

  • since 1.2
Sourceval select : t -> 'a array -> 'a list

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.

Sourceval selecti : t -> 'a array -> ('a * int) list

Same as select, but selected elements are paired with their indexes.

Sourcetype 'a sequence = ('a -> unit) -> unit
Sourceval to_seq : t -> int sequence
Sourceval of_seq : int sequence -> t
Sourceval pp : Format.formatter -> t -> unit

Print the bitvector as a string of bits.

  • since 0.13
OCaml

Innovation. Community. Security.