mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
parent
a642aa6f6b
commit
92519b4843
1 changed files with 10 additions and 12 deletions
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue