Method: NetworkX::UnionFind#root

Defined in:
lib/networkx/auxillary_functions/union_find.rb

#root(node) ⇒ Object

Return the root of node



47
48
49
50
51
# File 'lib/networkx/auxillary_functions/union_find.rb', line 47

def root(node)
  @parents.has_key?(node) or raise ArgumentError.new, "#{node} is not a node"

  @parents[node] == node ? node : (@parents[node] = root(@parents[node]))
end