Class: Rinda::TupleBag::DomainTupleBin Private

Inherits:
TupleBin
  • Object
show all
Defined in:
lib/pione/patch/rinda-patch.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

DomainTupleBin should take tuples that have domain.

DomainTupleBin is a domain based TupleBin class.

Instance Method Summary collapse

Methods inherited from TupleBin

#size

Constructor Details

#initializeDomainTupleBin

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new bin.



126
127
128
# File 'lib/pione/patch/rinda-patch.rb', line 126

def initialize
  @bin = {}
end

Instance Method Details

#add(tuple) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Add the tuple into the tuple space.

Parameters:

  • tuple (Array)

    the tuple



135
136
137
138
139
140
141
# 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) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Deletes the tuple.

Parameters:

  • tuple (Array)

    the tuple



147
148
149
# File 'lib/pione/patch/rinda-patch.rb', line 147

def delete(tuple)
  @bin.delete(domain(tuple))
end

#delete_if {|Array| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Deletes tuples that match the block.

Yields:



155
156
157
158
# 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) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an iterator of the values.

Returns:

  • (Enumerator)

    iterator of the values



204
205
206
# File 'lib/pione/patch/rinda-patch.rb', line 204

def each(*args)
  @bin.values.each(*args)
end

#elementsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



160
161
162
# File 'lib/pione/patch/rinda-patch.rb', line 160

def elements
  @bin.values
end

#find(template) {|Array| ... } ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds a tuple matched by the template. This method searches by index when the template has the domain, otherwise by liner.

Parameters:

  • template (TemplateEntry)

    template tuple

Yields:

  • (Array)

    match condition block

Returns:

  • (Array)

    a matched tuple



172
173
174
175
176
177
178
179
180
# 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) {|Array| ... } ⇒ Array<Array>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds all tuples matched by the template. This method searches by index when the template has the domain, otherwise by liner.

Parameters:

  • template (TemplateEntry)

    template tuple

Yields:

  • (Array)

    match condition block

Returns:



190
191
192
193
194
195
196
197
198
199
# 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