[istd] refactor of ImperativeUnionFind to expose [find_opt] later

Summary: I think this does the same thing as before.

Reviewed By: skcho

Differential Revision: D22576002

fbshipit-source-id: 8317dd82e
master
Jules Villard 4 years ago committed by Facebook GitHub Bot
parent 9578ec74c9
commit 2dc830735e

@ -57,16 +57,19 @@ module Make (Set : Set) = struct
let is_a_repr (t : t) e = not (H.mem t e)
let rec find (t : t) e : Repr.t =
match H.find_opt t e with
let rec find_opt (t : t) e : Repr.t option =
H.find_opt t e
|> Option.map ~f:(fun (r : Repr.t) ->
match find_opt t (r :> Set.elt) with
| None ->
Repr.of_elt e
| Some r ->
let r' = find t (r :> Set.elt) in
r
| Some r' ->
if not (phys_equal r r') then H.replace t e r' ;
r'
r' )
let find (t : t) e : Repr.t = match find_opt t e with Some r -> r | None -> Repr.of_elt e
let merge (t : t) ~(from : Repr.t) ~(to_ : Repr.t) = H.replace t (from :> Set.elt) to_
end

Loading…
Cancel
Save