[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,15 +57,18 @@ 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
| None -> |> Option.map ~f:(fun (r : Repr.t) ->
Repr.of_elt e match find_opt t (r :> Set.elt) with
| Some r -> | None ->
let r' = find t (r :> Set.elt) in r
if not (phys_equal r r') then H.replace t e r' ; | Some r' ->
r' if not (phys_equal r r') then H.replace t e 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