Class Rinda::TupleBag
In: lib/rinda/tuplespace.rb
Parent: Object

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

Methods

Classes and Modules

Class Rinda::TupleBag::TupleBin

Public Instance methods

Removes tuple from the TupleBag.

[Source]

     # File lib/rinda/tuplespace.rb, line 342
342:     def delete(tuple)
343:       key = bin_key(tuple)
344:       bin = @hash[key]
345:       return nil unless bin
346:       bin.delete(tuple)
347:       @hash.delete(key) if bin.empty?
348:       tuple
349:     end

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

[Source]

     # File lib/rinda/tuplespace.rb, line 382
382:     def delete_unless_alive
383:       deleted = []
384:       @hash.each do |key, bin|
385:         bin.delete_if do |tuple|
386:           if tuple.alive?
387:             false
388:           else
389:             deleted.push(tuple)
390:             true
391:           end
392:         end
393:       end
394:       deleted
395:     end

Finds a live tuple that matches template.

[Source]

     # File lib/rinda/tuplespace.rb, line 362
362:     def find(template)
363:       bin_for_find(template).find do |tuple|
364:         tuple.alive? && template.match(tuple)
365:       end
366:     end

Finds all live tuples that match template.

[Source]

     # File lib/rinda/tuplespace.rb, line 353
353:     def find_all(template)
354:       bin_for_find(template).find_all do |tuple|
355:         tuple.alive? && template.match(tuple)
356:       end
357:     end

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

[Source]

     # File lib/rinda/tuplespace.rb, line 372
372:     def find_all_template(tuple)
373:       @enum.find_all do |template|
374:         template.alive? && template.match(tuple)
375:       end
376:     end

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

[Source]

     # File lib/rinda/tuplespace.rb, line 324
324:     def has_expires?
325:       @enum.find do |tuple|
326:         tuple.expires
327:       end
328:     end

Add tuple to the TupleBag.

[Source]

     # File lib/rinda/tuplespace.rb, line 333
333:     def push(tuple)
334:       key = bin_key(tuple)
335:       @hash[key] ||= TupleBin.new
336:       @hash[key].add(tuple)
337:     end

Private Instance methods

[Source]

     # File lib/rinda/tuplespace.rb, line 413
413:     def bin_for_find(template)
414:       key = bin_key(template)
415:       key ? @hash.fetch(key, []) : @enum
416:     end

[Source]

     # File lib/rinda/tuplespace.rb, line 404
404:     def bin_key(tuple)
405:       head = tuple[0]
406:       if head.class == Symbol
407:         return head
408:       else
409:         false
410:       end
411:     end

[Source]

     # File lib/rinda/tuplespace.rb, line 398
398:     def each_entry(&blk)
399:       @hash.each do |k, v|
400:         v.each(&blk)
401:       end
402:     end

[Validate]