Class: CycleDetector
- Inherits:
-
Object
- Object
- CycleDetector
- Defined in:
- lib/cpp_dependency_graph/cycle_detector.rb
Overview
Detects cycles between nodes
Instance Method Summary collapse
- #cyclic?(source, target) ⇒ Boolean
-
#initialize(links) ⇒ CycleDetector
constructor
A new instance of CycleDetector.
- #to_s ⇒ Object
Constructor Details
#initialize(links) ⇒ CycleDetector
Returns a new instance of CycleDetector.
7 8 9 10 11 12 13 |
# File 'lib/cpp_dependency_graph/cycle_detector.rb', line 7 def initialize(links) @cyclic_links = links.flat_map do |source, source_links| source_links.select { |target| links[target].include?(source) }.map do |target| [CyclicLink.new(source, target), true] end end.to_h end |
Instance Method Details
#cyclic?(source, target) ⇒ Boolean
15 16 17 18 |
# File 'lib/cpp_dependency_graph/cycle_detector.rb', line 15 def cyclic?(source, target) k = CyclicLink.new(source, target) @cyclic_links.key?(k) end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/cpp_dependency_graph/cycle_detector.rb', line 20 def to_s @cyclic_links.keys end |