Class: Tumugi::DAG
- Inherits:
-
Object
- Object
- Tumugi::DAG
- Includes:
- TSort, Mixin::Listable
- Defined in:
- lib/tumugi/dag.rb
Instance Attribute Summary collapse
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Instance Method Summary collapse
- #add_task(task) ⇒ Object
-
#initialize ⇒ DAG
constructor
A new instance of DAG.
- #tsort_each_child(node, &block) ⇒ Object
- #tsort_each_node(&block) ⇒ Object
Methods included from Mixin::Listable
Constructor Details
#initialize ⇒ DAG
Returns a new instance of DAG.
11 12 13 |
# File 'lib/tumugi/dag.rb', line 11 def initialize @tasks = {} end |
Instance Attribute Details
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
9 10 11 |
# File 'lib/tumugi/dag.rb', line 9 def tasks @tasks end |
Instance Method Details
#add_task(task) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tumugi/dag.rb', line 23 def add_task(task) t = task.instance unless @tasks[t] reqs = list(t._requires).map {|r| r.instance } @tasks[t] = reqs reqs.each do |r| add_task(r) end end task end |
#tsort_each_child(node, &block) ⇒ Object
19 20 21 |
# File 'lib/tumugi/dag.rb', line 19 def tsort_each_child(node, &block) @tasks.fetch(node).each(&block) end |
#tsort_each_node(&block) ⇒ Object
15 16 17 |
# File 'lib/tumugi/dag.rb', line 15 def tsort_each_node(&block) @tasks.each_key(&block) end |