From 79d4129d11e9f88b0456ae7213eadd42a64716b5 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 26 Nov 2013 15:46:40 +0100 Subject: [PATCH] added BV.select/selecti (break api) functions --- BV.ml | 12 ++++++++++++ BV.mli | 12 +++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/BV.ml b/BV.ml index 9f9bd00f..34f9a99a 100644 --- a/BV.ml +++ b/BV.ml @@ -200,6 +200,18 @@ let inter bv1 bv2 = bv 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 begin try iter_true bv diff --git a/BV.mli b/BV.mli index 4d6e85e7..c32701bc 100644 --- a/BV.mli +++ b/BV.mli @@ -86,7 +86,6 @@ val filter : t -> (int -> bool) -> unit val union_into : into:t -> t -> unit (** [union ~into bv] sets [into] to the union of itself and [bv]. *) - val inter_into : into:t -> t -> unit (** [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 (** 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 - correspond to a true bit in [bv]. The elements are paired to their - index in [arr]. If [bv] is too short, elements of [arr] with too high - an index cannot be returned. *) + correspond 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. *) + +val selecti : t -> 'a array -> ('a * int) list + (** Same as {!select}, but selected elements are paired with their index *)