package io.mirango;

public class UnionFind {

}

@@ -18,32 +18,928 @@
 o;%0A%0A
-public class UnionFind %7B
+import java.util.HashMap;%0Aimport java.util.stream.Stream;%0A%0Apublic class UnionFind %7B%0A    private Stream%3CVertex%3CPoint%3E%3E v;%0A    private HashMap%3CVertex%3CPoint%3E, Vertex%3CPoint%3E%3E parent;%0A    private HashMap%3CVertex%3CPoint%3E, Integer%3E rank;%0A%0A    public UnionFind(Stream%3CVertex%3CPoint%3E%3E pts) %7B%0A        v = pts;%0A        v.forEach(x -%3E %7B%0A            parent.put(x, x);%0A            rank.put(x, 1);%0A        %7D);%0A    %7D%0A%0A    public Vertex%3CPoint%3E Find(Vertex%3CPoint%3E a) %7B%0A        if (parent.get(a).equals(a)) %7B%0A            return a;%0A        %7D else %7B%0A            return Find(parent.get(a));%0A        %7D%0A    %7D%0A%0A    public void Union(Vertex%3CPoint%3E a, Vertex%3CPoint%3E b) %7B%0A        if (rank.get(a) %3E rank.get(b)) %7B%0A            parent.put(b, a);%0A        %7D else if (rank.get(b) %3E rank.get(a)) %7B%0A            parent.put(a, b);%0A        %7D else %7B%0A            parent.put(a, b);%0A            Integer i = rank.get(b);%0A            rank.put(b, ++i);%0A        %7D%0A%0A    %7D
 %0A%0A%7D%0A

add find and union methods to union find