[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 is_a_repr (t : t) e = not (H.mem t e)
let rec find (t : t) e : Repr.t = let rec find_opt (t : t) e : Repr.t option =
match H.find_opt t e with H.find_opt t e
|> Option.map ~f:(fun (r : Repr.t) ->
match find_opt t (r :> Set.elt) with
| None -> | None ->
Repr.of_elt e r
| Some r -> | Some r' ->
let r' = find t (r :> Set.elt) in
if not (phys_equal r r') then H.replace t e 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_ let merge (t : t) ~(from : Repr.t) ~(to_ : Repr.t) = H.replace t (from :> Set.elt) to_
end end

Loading…
Cancel
Save