instance method
TSort#tsort_each
() { (Node) -> void } -> void
() -> ::Enumerator[Node, void]
tsort_each() { |node| ... }
lib/tsort.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/tsort.rb, line 207
def tsort_each(&block) # :yields: node
each_node = method(:tsort_each_node)
each_child = method(:tsort_each_child)
TSort.tsort_each(each_node, each_child, &block)
end
The iterator version of the tsort method. <em>obj</em>.tsort_each is similar to <em>obj</em>.tsort.each, but modification of obj during the iteration may lead to unexpected results.
tsort_each returns nil. If there is a cycle, TSort::Cyclic is raised.
Example
class G include TSort def initialize(g) @g = g end def tsort_each_child(n, &b) @g[n].each(&b) end def tsort_each_node(&b) @g.each_key(&b) end end graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}) graph.tsort_each {|n| p n } #=> 4 # 2 # 3 # 1
See also
.tsort_each
#tsort
#tsort_each_child
#strongly_connected_components
also in
3.4 · 3.3 · 3.2 · 3.1 · 3.0