Class: Rinda::TupleBag
Overview
TupleBag is an unordered collection of tuples. It is the basis of Tuplespace.
Defined Under Namespace
Classes: TupleBin
Instance Method Summary (collapse)
-
- (Object) delete(tuple)
Removes tuple from the TupleBag.
-
- (Object) delete_unless_alive
Delete tuples which dead tuples from the TupleBag, returning the deleted tuples.
-
- (Object) find(template)
Finds a live tuple that matches template.
-
- (Object) find_all(template)
Finds all live tuples that match template.
-
- (Object) find_all_template(tuple)
Finds all tuples in the TupleBag which when treated as templates, match tuple and are alive.
-
- (Boolean) has_expires?
true if the TupleBag to see if it has any expired entries.
-
- (TupleBag) initialize
constructor
:nodoc:.
-
- (Object) push(tuple)
Add tuple to the TupleBag.
Constructor Details
- (TupleBag) initialize
:nodoc:
316 317 318 319 |
# File 'lib/rinda/tuplespace.rb', line 316 def initialize # :nodoc: @hash = {} @enum = enum_for(:each_entry) end |
Instance Method Details
- (Object) delete(tuple)
Removes tuple from the TupleBag.
342 343 344 345 346 347 348 349 |
# File 'lib/rinda/tuplespace.rb', line 342 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 |
- (Object) delete_unless_alive
Delete tuples which dead tuples from the TupleBag, returning the deleted tuples.
382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/rinda/tuplespace.rb', line 382 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 |
- (Object) find(template)
Finds a live tuple that matches template.
362 363 364 365 366 |
# File 'lib/rinda/tuplespace.rb', line 362 def find(template) bin_for_find(template).find do |tuple| tuple.alive? && template.match(tuple) end end |
- (Object) find_all(template)
Finds all live tuples that match template.
353 354 355 356 357 |
# File 'lib/rinda/tuplespace.rb', line 353 def find_all(template) bin_for_find(template).find_all do |tuple| tuple.alive? && template.match(tuple) end end |
- (Object) find_all_template(tuple)
Finds all tuples in the TupleBag which when treated as templates, match tuple and are alive.
372 373 374 375 376 |
# File 'lib/rinda/tuplespace.rb', line 372 def find_all_template(tuple) @enum.find_all do |template| template.alive? && template.match(tuple) end end |
- (Boolean) has_expires?
true if the TupleBag to see if it has any expired entries.
324 325 326 327 328 |
# File 'lib/rinda/tuplespace.rb', line 324 def has_expires? @enum.find do |tuple| tuple.expires end end |
- (Object) push(tuple)
Add tuple to the TupleBag.
333 334 335 336 337 |
# File 'lib/rinda/tuplespace.rb', line 333 def push(tuple) key = bin_key(tuple) @hash[key] ||= TupleBin.new @hash[key].add(tuple) end |