improve doc for BV

This commit is contained in:
Simon Cruanes 2022-07-04 22:04:40 -04:00
parent 30cb40c71f
commit d9717095ef
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 19 additions and 9 deletions

View file

@ -181,9 +181,11 @@ let resize_minimize_memory bv size =
grow_to_at_least_ bv size grow_to_at_least_ bv size
let is_empty bv = let is_empty bv =
bv.size = 0
||
try try
for i = 0 to Bytes.length bv.b - 1 do for i = 0 to bytes_length_of_size bv.size - 1 do
if get_ bv.b i <> 0 then raise_notrace Exit if unsafe_get_ bv.b i <> 0 then raise_notrace Exit
done; done;
true true
with Exit -> false with Exit -> false

View file

@ -17,10 +17,11 @@ type t
(** A resizable bitvector *) (** A resizable bitvector *)
val empty : unit -> t val empty : unit -> t
(** Empty bitvector. *) (** Empty bitvector. Length is 0. *)
val create : size:int -> bool -> t val create : size:int -> bool -> t
(** Create a bitvector of given size, with given default value. *) (** Create a bitvector of given size, with given default value.
Length of result is [size]. *)
val copy : t -> t val copy : t -> t
(** Copy of bitvector. *) (** Copy of bitvector. *)
@ -108,15 +109,17 @@ val first_exn : t -> int
val filter : t -> (int -> bool) -> unit val filter : t -> (int -> bool) -> unit
(** [filter bv p] only keeps the true bits of [bv] whose [index] (** [filter bv p] only keeps the true bits of [bv] whose [index]
satisfies [p index]. *) satisfies [p index].
Length is unchanged. *)
val negate_self : t -> unit val negate_self : t -> unit
(** [negate_self t] flips all of the bits in [t]. (** [negate_self t] flips all of the bits in [t]. Length is unchanged.
@since 1.2 *) @since 1.2 *)
val negate : t -> t val negate : t -> t
(** [negate t] returns a copy of [t] with all of the bits flipped. *) (** [negate t] returns a copy of [t] with all of the bits flipped.
Length is unchanged. *)
val union_into : into:t -> t -> unit val union_into : into:t -> t -> unit
(** [union_into ~into bv] sets [into] to the union of itself and [bv]. (** [union_into ~into bv] sets [into] to the union of itself and [bv].
@ -132,10 +135,12 @@ val inter_into : into:t -> t -> unit
*) *)
val union : t -> t -> t val union : t -> t -> t
(** [union bv1 bv2] returns the union of the two sets. *) (** [union bv1 bv2] returns the union of the two sets. The length
of the result is the max of the inputs' lengths. *)
val inter : t -> t -> t val inter : t -> t -> t
(** [inter bv1 bv2] returns the intersection of the two sets. *) (** [inter bv1 bv2] returns the intersection of the two sets. The length
of the result is the min of the inputs' lengths. *)
val diff_into : into:t -> t -> unit val diff_into : into:t -> t -> unit
(** [diff_into ~into t] modifies [into] with only the bits set but not in [t]. (** [diff_into ~into t] modifies [into] with only the bits set but not in [t].
@ -163,7 +168,10 @@ val equal : t -> t -> bool
type 'a iter = ('a -> unit) -> unit type 'a iter = ('a -> unit) -> unit
val to_iter : t -> int iter val to_iter : t -> int iter
(** Iterate over the true bits. *)
val of_iter : int iter -> t val of_iter : int iter -> t
(** Build from true bits. *)
val pp : Format.formatter -> t -> unit val pp : Format.formatter -> t -> unit
(** Print the bitvector as a string of bits. (** Print the bitvector as a string of bits.