File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -1087,11 +1087,31 @@ struct
1087
1087
| Leaf ->
1088
1088
s1
1089
1089
1090
- (* TODO: LDB: implement linear union *)
1090
+ let rec merge size xs ys =
1091
+ match xs, ys with
1092
+ | [] , _ -> size, ys
1093
+ | _ , [] -> size, xs
1094
+ | x :: tx , y :: ty ->
1095
+ if Ord. compare x y = 0
1096
+ then let s, rs = merge (pred size) tx ty in
1097
+ s, x :: rs
1098
+ else if Ord. compare x y < 0
1099
+ then let s, rs = merge size tx ys in
1100
+ s, x :: rs
1101
+ else let s, rs = merge size xs ty in
1102
+ s, y :: rs
1103
+
1104
+ let compare_height x y =
1105
+ compare (log2 1 (succ x)) (log2 1 (succ y))
1106
+
1091
1107
let union s1 s2 =
1092
1108
let size1 = cardinality s1 in
1093
1109
let size2 = cardinality s2 in
1094
- if size1 < size2 then
1110
+ let comp = compare_height size1 size2 in
1111
+ if comp = 0 then
1112
+ let s, l = (merge (size1 + size2 + 1 ) (to_list s1) (to_list s2)) in
1113
+ treeify s l
1114
+ else if comp < 0 then
1095
1115
union_aux s2 s1
1096
1116
else
1097
1117
union_aux s1 s2
You can’t perform that action at this time.
0 commit comments