| In: |
rinda/tuplespace.rb
|
| Parent: | Object |
TupleBag is an unordered collection of tuples. It is the basis of Tuplespace.
Delete tuples which are not alive from the TupleBag. Returns the list of tuples so deleted.
# 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.
# 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.
# 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