find method

T find(
  1. T item
)

Finds the representative (root) of the set that contains item, applying path compression for efficiency.

Implementation

T find(T item) {
  if (_parent[item] != item) {
    _parent[item] = find(_parent[item] as T);
  }
  return _parent[item]!;
}