module M = Map.Make(String)

(* fiecare sir are ca si corespondenta un sir echivalent
 * un sir fara corespondenta e propriul reprezentant
 * pentru orice alt sir urmam lantul pana la capat *)
                   
let find m =        (* dictionarul m e acelasi la fiecare apel *)
  (* daca are reprezentant, continua cu el, altfel returneaza x *)
  let rec find1 x = try find1 (M.find x m) with Not_found -> x
  in find1

(* gaseste reprezentantii, apoi ii face echivalenti *)
let union m x y =
  let rx = find m x and ry = find m y in
  if rx = ry then m else M.add rx ry m        (* rx indica acum spre ry *)


This document was generated using caml2html