Sha256: b25521163ac4b9e385798ea0319b9ed512bc4aa68bdc084b690f851f75701362

Contents?: true

Size: 550 Bytes

Versions: 1

Compression:

Stored size: 550 Bytes

Contents

module Pregel
  class Worker
    attr_reader :vertices, :active

    def initialize(graph = [])
      raise 'empty worker graph' if graph.empty?
      @vertices = graph
      @active   = graph.size
    end

    def superstep
      Thread.new do
        @vertices.each do |v|
          v.messages = PostOffice.instance.read(v.id)
          v.active! if v.messages.size > 0
        end

        active = @vertices.select {|v| v.active?}
        active.each {|v| v.step}

        @active = active.select {|v| v.active?}.size
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pregel-0.0.1 lib/pregel/worker.rb