mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
feat(BV): add init
This commit is contained in:
parent
b24feaf2d6
commit
e15971934d
2 changed files with 13 additions and 1 deletions
|
|
@ -67,7 +67,7 @@ let bytes_length_of_size size =
|
|||
else
|
||||
div_ size + 1
|
||||
|
||||
let create ~size default =
|
||||
let create ~size default : t =
|
||||
if size = 0 then
|
||||
empty ()
|
||||
else (
|
||||
|
|
@ -210,6 +210,13 @@ let[@inline] set bv i =
|
|||
(unsafe_get_ bv.b idx_bucket lor (1 lsl idx_in_byte))
|
||||
)
|
||||
|
||||
let init size f : t =
|
||||
let v = create ~size false in
|
||||
for i = 0 to size - 1 do
|
||||
if f i then set v i
|
||||
done;
|
||||
v
|
||||
|
||||
let[@inline] reset bv i =
|
||||
if i < 0 then
|
||||
invalid_arg "reset: negative index"
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ val create : size:int -> bool -> t
|
|||
(** Create a bitvector of given size, with given default value.
|
||||
Length of result is [size]. *)
|
||||
|
||||
val init : int -> (int -> bool) -> t
|
||||
(** [init len f] initializes a bitvector of length [len], where bit [i]
|
||||
is true iff [f i] is.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val copy : t -> t
|
||||
(** Copy of bitvector. *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue