class Rinda::TupleBag::DomainTupleBin

DomainTupleBin is a domain based TupleBin class. @note

DomainTupleBin should take tuples that have domain.

Public Class Methods

new() click to toggle source

Creates a new bin.

# File lib/pione/patch/rinda-patch.rb, line 126
def initialize
  @bin = {}
end

Public Instance Methods

add(tuple) click to toggle source

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
delete(tuple) click to toggle source

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
delete_if() { |val| ... } click to toggle source

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
each(*args) click to toggle source

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
elements() click to toggle source
# File lib/pione/patch/rinda-patch.rb, line 160
def elements
  @bin.values
end
find(template) { |val| ... } click to toggle source

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
find_all(template) { |val| ... } click to toggle source

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

domain(tuple) click to toggle source

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