Skip to content

Commit

Permalink
Fix an issue in the union
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Dec 20, 2024
1 parent 6e6b85a commit 9f1ceaf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index-format/union_find.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ let rec find x =
match x.content with
| Root _ -> x
| Link ({ parent; _ } as link) ->
let parent' = find parent in
if parent' <> parent then link.parent <- parent';
parent'
let root = find parent in
if root <> parent then link.parent <- root;
root

let union ~f x y =
match (find x, find y) with
let x = find x in
let y = find y in
match (x, y) with
| x, y when x == y -> x
| ( { content = Root ({ rank = rank_x; value = value_x } as root_x); _ },
{ content = Root ({ rank = rank_y; value = value_y } as root_y); _ } ) ->
Expand Down

0 comments on commit 9f1ceaf

Please sign in to comment.