Class: Pregel::Vertex
- Inherits:
-
Object
- Object
- Pregel::Vertex
- Defined in:
- lib/pregel/vertex.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #active! ⇒ Object
- #active? ⇒ Boolean
- #compute ⇒ Object
- #deliver(to, msg) ⇒ Object
- #deliver_to_all_neighbors(msg) ⇒ Object
- #edges ⇒ Object
- #halt ⇒ Object
-
#initialize(id, value, *outedges) ⇒ Vertex
constructor
A new instance of Vertex.
- #neighbors ⇒ Object
- #step ⇒ Object
- #superstep ⇒ Object
Constructor Details
#initialize(id, value, *outedges) ⇒ Vertex
Returns a new instance of Vertex.
6 7 8 9 10 11 12 13 |
# File 'lib/pregel/vertex.rb', line 6 def initialize(id, value, *outedges) @id = id @value = value @outedges = outedges @messages = [] @active = true @superstep = 0 end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/pregel/vertex.rb', line 3 def id @id end |
#messages ⇒ Object
Returns the value of attribute messages.
4 5 6 |
# File 'lib/pregel/vertex.rb', line 4 def @messages end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/pregel/vertex.rb', line 4 def value @value end |
Instance Method Details
#active! ⇒ Object
33 |
# File 'lib/pregel/vertex.rb', line 33 def active!; @active = true; end |
#active? ⇒ Boolean
34 |
# File 'lib/pregel/vertex.rb', line 34 def active?; @active; end |
#compute ⇒ Object
39 |
# File 'lib/pregel/vertex.rb', line 39 def compute; end |
#deliver(to, msg) ⇒ Object
23 24 25 |
# File 'lib/pregel/vertex.rb', line 23 def deliver(to, msg) PostOffice.instance.deliver(to, msg) end |
#deliver_to_all_neighbors(msg) ⇒ Object
19 20 21 |
# File 'lib/pregel/vertex.rb', line 19 def deliver_to_all_neighbors(msg) edges.each {|e| deliver(e, msg)} end |
#edges ⇒ Object
15 16 17 |
# File 'lib/pregel/vertex.rb', line 15 def edges block_given? ? @outedges.each {|e| yield e} : @outedges end |
#halt ⇒ Object
32 |
# File 'lib/pregel/vertex.rb', line 32 def halt; @active = false; end |
#neighbors ⇒ Object
37 |
# File 'lib/pregel/vertex.rb', line 37 def neighbors; @outedges; end |
#step ⇒ Object
27 28 29 30 |
# File 'lib/pregel/vertex.rb', line 27 def step @superstep += 1 compute end |
#superstep ⇒ Object
36 |
# File 'lib/pregel/vertex.rb', line 36 def superstep; @superstep; end |