Rinda::TupleBag (Class)

In: rinda/tuplespace.rb
Parent: Object

TupleBag is an unordered collection of tuples. It is the basis of Tuplespace.

Methods

Public Class methods

[Source]

# File rinda/tuplespace.rb, line 219
    def initialize
      @hash = {}
    end

Public Instance methods

Remove the object from the TupleBag.

[Source]

# File rinda/tuplespace.rb, line 231
    def delete(ary)
      size = ary.size
      @hash.fetch(size, []).delete(ary)
    end

Delete tuples which are not alive from the TupleBag. Returns the list of tuples so deleted.

[Source]

# File rinda/tuplespace.rb, line 260
    def delete_unless_alive
      deleted = []
      @hash.keys.each do |size|
        ary = []
        @hash[size].each do |tuple|
          if tuple.alive?
            ary.push(tuple)
          else
            deleted.push(tuple)
          end
        end
        @hash[size] = ary
      end
      deleted
    end

Finds a template that matches and is alive.

[Source]

# File rinda/tuplespace.rb, line 244
    def find(template)
      @hash.fetch(template.size, []).find do |tuple|
        tuple.alive? && template.match(tuple)
      end
    end

Finds all tuples that match the template and are alive.

[Source]

# File rinda/tuplespace.rb, line 237
    def find_all(template)
      @hash.fetch(template.size, []).find_all do |tuple|
        tuple.alive? && template.match(tuple)
      end
    end

Finds all tuples in the TupleBag which when treated as templates, match the supplied tuple and are alive.

[Source]

# File rinda/tuplespace.rb, line 252
    def find_all_template(tuple)
      @hash.fetch(tuple.size, []).find_all do |template|
        template.alive? && template.match(tuple)
      end
    end

Add the object to the TupleBag.

[Source]

# File rinda/tuplespace.rb, line 224
    def push(ary)
      size = ary.size
      @hash[size] ||= []
      @hash[size].push(ary)
    end

[Validate]