Class: Compute::ComputationGraph

Inherits:
Hash
  • Object
show all
Includes:
TSort
Defined in:
lib/compute/computation_graph.rb

Instance Method Summary collapse

Constructor Details

#initializeComputationGraph

Returns a new instance of ComputationGraph.



11
12
13
14
15
16
# File 'lib/compute/computation_graph.rb', line 11

def initialize
  @sorted_computations = []
  @computations_for_changed_properties = Hash.new do |h, changed_properties|
    @sorted_computations.select { |c| c.needs_update?(changed_properties) }
  end
end

Instance Method Details

#<<(computation) ⇒ Object



18
19
20
21
# File 'lib/compute/computation_graph.rb', line 18

def <<(computation)
  self[computation.property] = computation
  sort!
end

#each_in_orderObject



23
24
25
# File 'lib/compute/computation_graph.rb', line 23

def each_in_order
  @sorted_computations.each { |c| yield c }
end

#for_changed_properties(changed_properties) ⇒ Object



31
32
33
# File 'lib/compute/computation_graph.rb', line 31

def for_changed_properties(changed_properties)
  @computations_for_changed_properties[changed_properties]
end

#for_property(property) ⇒ Object



27
28
29
# File 'lib/compute/computation_graph.rb', line 27

def for_property(property)
  self[property.to_sym]
end