Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/tsort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def tsort
# each_child = lambda {|n, &b| g[n].each(&b) }
# p TSort.tsort(each_node, each_child) # raises TSort::Cyclic
#
def TSort.tsort(each_node, each_child)
TSort.tsort_each(each_node, each_child).to_a
def self.tsort(each_node, each_child)
tsort_each(each_node, each_child).to_a
end

# The iterator version of the #tsort method.
Expand Down Expand Up @@ -220,10 +220,10 @@ def tsort_each(&block) # :yields: node
# # 3
# # 1
#
def TSort.tsort_each(each_node, each_child) # :yields: node
def self.tsort_each(each_node, each_child) # :yields: node
return to_enum(__method__, each_node, each_child) unless block_given?

TSort.each_strongly_connected_component(each_node, each_child) {|component|
each_strongly_connected_component(each_node, each_child) {|component|
if component.size == 1
yield component.first
else
Expand Down Expand Up @@ -277,8 +277,8 @@ def strongly_connected_components
# p TSort.strongly_connected_components(each_node, each_child)
# #=> [[4], [2, 3], [1]]
#
def TSort.strongly_connected_components(each_node, each_child)
TSort.each_strongly_connected_component(each_node, each_child).to_a
def self.strongly_connected_components(each_node, each_child)
each_strongly_connected_component(each_node, each_child).to_a
end

# The iterator version of the #strongly_connected_components method.
Expand Down Expand Up @@ -339,14 +339,14 @@ def each_strongly_connected_component(&block) # :yields: nodes
# # [2, 3]
# # [1]
#
def TSort.each_strongly_connected_component(each_node, each_child) # :yields: nodes
def self.each_strongly_connected_component(each_node, each_child) # :yields: nodes
return to_enum(__method__, each_node, each_child) unless block_given?

id_map = {}
stack = []
each_node.call {|node|
unless id_map.include? node
TSort.each_strongly_connected_component_from(node, each_child, id_map, stack) {|c|
each_strongly_connected_component_from(node, each_child, id_map, stack) {|c|
yield c
}
end
Expand Down Expand Up @@ -405,7 +405,7 @@ def each_strongly_connected_component_from(node, id_map={}, stack=[], &block) #
# # [2, 3]
# # [1]
#
def TSort.each_strongly_connected_component_from(node, each_child, id_map={}, stack=[]) # :yields: nodes
def self.each_strongly_connected_component_from(node, each_child, id_map={}, stack=[]) # :yields: nodes
return to_enum(__method__, node, each_child, id_map, stack) unless block_given?

minimum_id = node_id = id_map[node] = id_map.size
Expand All @@ -418,7 +418,7 @@ def TSort.each_strongly_connected_component_from(node, each_child, id_map={}, st
minimum_id = child_id if child_id && child_id < minimum_id
else
sub_minimum_id =
TSort.each_strongly_connected_component_from(child, each_child, id_map, stack) {|c|
each_strongly_connected_component_from(child, each_child, id_map, stack) {|c|
yield c
}
minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
Expand Down