Class: Pregel::Worker
- Inherits:
-
Object
- Object
- Pregel::Worker
- Defined in:
- lib/pregel/worker.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#vertices ⇒ Object
readonly
Returns the value of attribute vertices.
Instance Method Summary collapse
-
#initialize(graph = []) ⇒ Worker
constructor
A new instance of Worker.
- #superstep ⇒ Object
Constructor Details
#initialize(graph = []) ⇒ Worker
Returns a new instance of Worker.
5 6 7 8 9 |
# File 'lib/pregel/worker.rb', line 5 def initialize(graph = []) raise 'empty worker graph' if graph.empty? @vertices = graph @active = graph.size end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
3 4 5 |
# File 'lib/pregel/worker.rb', line 3 def active @active end |
#vertices ⇒ Object (readonly)
Returns the value of attribute vertices.
3 4 5 |
# File 'lib/pregel/worker.rb', line 3 def vertices @vertices end |
Instance Method Details
#superstep ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pregel/worker.rb', line 11 def superstep Thread.new do @vertices.each do |v| v. = PostOffice.instance.read(v.id) v.active! if v..size > 0 end active = @vertices.select {|v| v.active?} active.each {|v| v.step} @active = active.select {|v| v.active?}.size end end |