mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
added BV.select/selecti (break api) functions
This commit is contained in:
parent
8e6a648502
commit
79d4129d11
2 changed files with 19 additions and 5 deletions
12
BV.ml
12
BV.ml
|
|
@ -200,6 +200,18 @@ let inter bv1 bv2 =
|
||||||
bv
|
bv
|
||||||
|
|
||||||
let select bv arr =
|
let select bv arr =
|
||||||
|
let l = ref [] in
|
||||||
|
begin try
|
||||||
|
iter_true bv
|
||||||
|
(fun i ->
|
||||||
|
if i >= Array.length arr
|
||||||
|
then raise Exit
|
||||||
|
else l := arr.(i) :: !l)
|
||||||
|
with Exit -> ()
|
||||||
|
end;
|
||||||
|
!l
|
||||||
|
|
||||||
|
let selecti bv arr =
|
||||||
let l = ref [] in
|
let l = ref [] in
|
||||||
begin try
|
begin try
|
||||||
iter_true bv
|
iter_true bv
|
||||||
|
|
|
||||||
12
BV.mli
12
BV.mli
|
|
@ -87,7 +87,6 @@ val filter : t -> (int -> bool) -> unit
|
||||||
val union_into : into:t -> t -> unit
|
val union_into : into:t -> t -> unit
|
||||||
(** [union ~into bv] sets [into] to the union of itself and [bv]. *)
|
(** [union ~into bv] sets [into] to the union of itself and [bv]. *)
|
||||||
|
|
||||||
|
|
||||||
val inter_into : into:t -> t -> unit
|
val inter_into : into:t -> t -> unit
|
||||||
(** [union ~into bv] sets [into] to the intersection of itself and [bv] *)
|
(** [union ~into bv] sets [into] to the intersection of itself and [bv] *)
|
||||||
|
|
||||||
|
|
@ -97,8 +96,11 @@ val union : t -> t -> t
|
||||||
val inter : t -> t -> t
|
val inter : t -> t -> t
|
||||||
(** Intersection of bitvectors *)
|
(** Intersection of bitvectors *)
|
||||||
|
|
||||||
val select : t -> 'a array -> ('a * int) list
|
val select : t -> 'a array -> 'a list
|
||||||
(** [select arr bv] selects the elements of [arr] whose index
|
(** [select arr bv] selects the elements of [arr] whose index
|
||||||
correspond to a true bit in [bv]. The elements are paired to their
|
correspond to a true bit in [bv]. If [bv] is too short, elements of [arr]
|
||||||
index in [arr]. If [bv] is too short, elements of [arr] with too high
|
with too high an index cannot be selected and are therefore not
|
||||||
an index cannot be returned. *)
|
selected. *)
|
||||||
|
|
||||||
|
val selecti : t -> 'a array -> ('a * int) list
|
||||||
|
(** Same as {!select}, but selected elements are paired with their index *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue