Class: Interdependence::Graph
- Inherits:
-
Hash
- Object
- Hash
- Interdependence::Graph
- Includes:
- TSort
- Defined in:
- lib/interdependence/graph.rb
Overview
Graph data structure - Topologically sortable
-
Accessing any key will initialize that key to a new empty set.
-
Topologically sortable using ‘tsort`
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize ⇒ undefined
constructor
private
Create a new graph utilizing Hash#default_proc.
-
#tsort_each_child(node) { ... } ⇒ undefined
private
Iterate over each child in the graph for TSort.
-
#tsort_fetch(key) ⇒ Object
private
Fetch a key for tsort and fallback to #default_value.
Constructor Details
#initialize ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new graph utilizing Hash#default_proc
#default_proc usage initializes new keys to #default_value
27 28 29 30 31 |
# File 'lib/interdependence/graph.rb', line 27 def initialize super do |hash, key| hash[key] = default_value end end |
Instance Method Details
#tsort_each_child(node) { ... } ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterate over each child in the graph for TSort
67 68 69 |
# File 'lib/interdependence/graph.rb', line 67 def tsort_each_child(node, &block) tsort_fetch(node).each(&block) end |
#tsort_fetch(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetch a key for tsort and fallback to #default_value
‘tsort_fetch` returns a new #default_value like `#[]` when `key` is not found. The fallback value is not added to the graph though since we do not want to mutate the graph during iteration
87 88 89 |
# File 'lib/interdependence/graph.rb', line 87 def tsort_fetch(key) fetch(key) { default_value } end |