public V componentOf ( V i ) { final V parent = parents . getOrDefault ( i , i ) ; if ( parent . equals ( i ) ) { return i ; } else { // collapse, so next lookup is O(1) parents . put ( i , componentOf ( parent ) ) ; } return parents . get ( i ) ; }
Find the representative for the given item