Skip to content

Commit

Permalink
fix(bv): index error in union
Browse files Browse the repository at this point in the history
close #370
  • Loading branch information
c-cube committed May 17, 2021
1 parent a642aa6 commit 92519b4
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/data/CCBV.ml
Original file line number Diff line number Diff line change
Expand Up @@ -423,32 +423,30 @@ let negate b =
Q.small_int (fun size -> create ~size false |> negate |> cardinal = size)
*)

let union_into_no_resize_ ~into bv =
assert (Array.length into.a >= Array.length bv.a);
for i = 0 to Array.length bv.a - 1 do
Array.unsafe_set into.a i
((Array.unsafe_get into.a i) lor (Array.unsafe_get bv.a i))
done

(* Underlying size grows for union. *)
let union_into ~into bv =
if into.size < bv.size then (
grow_ into bv.size;
);
for i = 0 to (Array.length into.a) - 1 do
Array.unsafe_set into.a i
((Array.unsafe_get into.a i) lor (Array.unsafe_get bv.a i))
done
union_into_no_resize_ ~into bv

(* To avoid potentially 2 passes, figure out what we need to copy. *)
let union b1 b2 =
if b1.size <= b2.size
then (
let into = copy b2 in
for i = 0 to (Array.length b1.a) - 1 do
Array.unsafe_set into.a i
((Array.unsafe_get into.a i) lor (Array.unsafe_get b1.a i))
done;
union_into_no_resize_ ~into b1;
into
) else (
let into = copy b1 in
for i = 0 to (Array.length b1.a) - 1 do
Array.unsafe_set into.a i
((Array.unsafe_get into.a i) lor (Array.unsafe_get b2.a i))
done;
union_into_no_resize_ ~into b2;
into
)

Expand Down

0 comments on commit 92519b4

Please sign in to comment.