class Rinda::TupleBag::DomainTupleBin
DomainTupleBin
is a domain based TupleBin
class. @note
DomainTupleBin should take tuples that have domain.
Public Class Methods
Creates a new bin.
# File lib/pione/patch/rinda-patch.rb, line 126 def initialize @bin = {} end
Public Instance Methods
Add the tuple into the tuple space.
@param [Array] tuple
the tuple
@return [void]
# File lib/pione/patch/rinda-patch.rb, line 135 def add(tuple) if dom = domain(tuple) @bin[dom] = tuple else raise RuntimeError end end
Deletes the tuple. @param [Array] tuple
the tuple
@return [void]
# File lib/pione/patch/rinda-patch.rb, line 147 def delete(tuple) @bin.delete(domain(tuple)) end
Deletes tuples that match the block. @yield [Array]
each tuple
@return [void]
# File lib/pione/patch/rinda-patch.rb, line 155 def delete_if return @bin unless block_given? @bin.delete_if {|key, val| yield(val)} end
Returns an iterator of the values. @return [Enumerator]
iterator of the values
# File lib/pione/patch/rinda-patch.rb, line 204 def each(*args) @bin.values.each(*args) end
# File lib/pione/patch/rinda-patch.rb, line 160 def elements @bin.values end
Finds a tuple matched by the template. This method searches by index when the template has the domain, otherwise by liner. @param [TemplateEntry] template
template tuple
@yield [Array]
match condition block
@return [Array]
a matched tuple
# File lib/pione/patch/rinda-patch.rb, line 172 def find(template, &b) if key = domain(template) # indexed search return @bin[key] else # liner search return @bin.values.find {|val| yield(val)} end end
Finds all tuples matched by the template. This method searches by index when the template has the domain, otherwise by liner. @param [TemplateEntry] template
template tuple
@yield [Array]
match condition block
@return [Array<Array>]
matched tuples
# File lib/pione/patch/rinda-patch.rb, line 190 def find_all(template, &b) return @bin.values unless block_given? if key = domain(template) # indexed search return [@bin[key]] else # liner search return @bin.select{|_, val| yield(val)}.values end end
Private Instance Methods
Returns domain position. @param [Array] tuple
the tuple
@return [String]
the domain
# File lib/pione/patch/rinda-patch.rb, line 215 def domain(tuple) identifier = tuple.value[0] pos = Pione::TupleSpace[identifier].domain_position tuple.value[pos] end