each_strongly_connected_component_from(node, id_map={}, stack=[])
public
Show source
def each_strongly_connected_component_from(node, id_map={}, stack=[])
minimum_id = node_id = id_map[node] = id_map.size
stack_length = stack.length
stack << node
tsort_each_child(node) {|child|
if id_map.include? child
child_id = id_map[child]
minimum_id = child_id if child_id && child_id < minimum_id
else
sub_minimum_id =
each_strongly_connected_component_from(child, id_map, stack) {|c|
yield c
}
minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
end
}
if node_id == minimum_id
component = stack.slice!(stack_length .. -1)
component.each {|n| id_map[n] = nil}
yield component
end
minimum_id
end