Class: Rinda::TupleBag
- Inherits:
-
Object
- Object
- Rinda::TupleBag
- Defined in:
- lib/rinda/tuplespace.rb
Overview
TupleBag is an unordered collection of tuples. It is the basis of Tuplespace.
Defined Under Namespace
Classes: TupleBin
Instance Method Summary collapse
-
#delete(tuple) ⇒ Object
Removes
tuple
from the TupleBag. -
#delete_unless_alive ⇒ Object
Delete tuples which dead tuples from the TupleBag, returning the deleted tuples.
-
#find(template) ⇒ Object
Finds a live tuple that matches
template
. -
#find_all(template) ⇒ Object
Finds all live tuples that match
template
. -
#find_all_template(tuple) ⇒ Object
Finds all tuples in the TupleBag which when treated as templates, match
tuple
and are alive. -
#has_expires? ⇒ Boolean
true
if the TupleBag to see if it has any expired entries. -
#initialize ⇒ TupleBag
constructor
:nodoc:.
-
#push(tuple) ⇒ Object
Add
tuple
to the TupleBag.
Constructor Details
#initialize ⇒ TupleBag
:nodoc:
315 316 317 318 |
# File 'lib/rinda/tuplespace.rb', line 315 def initialize # :nodoc: @hash = {} @enum = enum_for(:each_entry) end |
Instance Method Details
#delete(tuple) ⇒ Object
Removes tuple
from the TupleBag.
341 342 343 344 345 346 347 348 |
# File 'lib/rinda/tuplespace.rb', line 341 def delete(tuple) key = bin_key(tuple) bin = @hash[key] return nil unless bin bin.delete(tuple) @hash.delete(key) if bin.empty? tuple end |
#delete_unless_alive ⇒ Object
Delete tuples which dead tuples from the TupleBag, returning the deleted tuples.
381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/rinda/tuplespace.rb', line 381 def delete_unless_alive deleted = [] @hash.each do |key, bin| bin.delete_if do |tuple| if tuple.alive? false else deleted.push(tuple) true end end end deleted end |
#find(template) ⇒ Object
Finds a live tuple that matches template
.
361 362 363 364 365 |
# File 'lib/rinda/tuplespace.rb', line 361 def find(template) bin_for_find(template).find do |tuple| tuple.alive? && template.match(tuple) end end |
#find_all(template) ⇒ Object
Finds all live tuples that match template
.
352 353 354 355 356 |
# File 'lib/rinda/tuplespace.rb', line 352 def find_all(template) bin_for_find(template).find_all do |tuple| tuple.alive? && template.match(tuple) end end |
#find_all_template(tuple) ⇒ Object
Finds all tuples in the TupleBag which when treated as templates, match tuple
and are alive.
371 372 373 374 375 |
# File 'lib/rinda/tuplespace.rb', line 371 def find_all_template(tuple) @enum.find_all do |template| template.alive? && template.match(tuple) end end |
#has_expires? ⇒ Boolean
true
if the TupleBag to see if it has any expired entries.
323 324 325 326 327 |
# File 'lib/rinda/tuplespace.rb', line 323 def has_expires? @enum.find do |tuple| tuple.expires end end |