In Files

  • rinda/tuplespace.rb

Rinda::TupleBag

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

Public Instance Methods

delete(ary) click to toggle source

Removes ary from the TupleBag.

 
               # File rinda/tuplespace.rb, line 318
def delete(ary)
  size = ary.size
  @hash.fetch(size, []).delete(ary)
end
            
delete_unless_alive() click to toggle source

Delete tuples which dead tuples from the TupleBag, returning the deleted tuples.

 
               # File rinda/tuplespace.rb, line 355
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
            
find(template) click to toggle source

Finds a live tuple that matches template.

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

Finds all live tuples that match template.

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

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

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

true if the TupleBag to see if it has any expired entries.

 
               # File rinda/tuplespace.rb, line 297
def has_expires?
  @hash.each do |k, v|
    v.each do |tuple|
      return true if tuple.expires
    end
  end
  false
end
            
push(ary) click to toggle source

Add ary to the TupleBag.

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

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus