mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 19:25:28 -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
|
else
|
||||||
div_ size + 1
|
div_ size + 1
|
||||||
|
|
||||||
let create ~size default =
|
let create ~size default : t =
|
||||||
if size = 0 then
|
if size = 0 then
|
||||||
empty ()
|
empty ()
|
||||||
else (
|
else (
|
||||||
|
|
@ -210,6 +210,13 @@ let[@inline] set bv i =
|
||||||
(unsafe_get_ bv.b idx_bucket lor (1 lsl idx_in_byte))
|
(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 =
|
let[@inline] reset bv i =
|
||||||
if i < 0 then
|
if i < 0 then
|
||||||
invalid_arg "reset: negative index"
|
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.
|
(** Create a bitvector of given size, with given default value.
|
||||||
Length of result is [size]. *)
|
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
|
val copy : t -> t
|
||||||
(** Copy of bitvector. *)
|
(** Copy of bitvector. *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue