class Rinda::TupleBag
TupleBag — это неупорядоченное множество кортежей. Он является основой пространства кортежей.
Общедоступные методы экземпляров
# 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
Удаляет tuple из TupleBag.
# 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 Удаляет мёртвые кортежи из TupleBag, возвращая удалённые кортежи.
# File lib/rinda/tuplespace.rb, line 362
def find(template)
bin_for_find(template).find do |tuple|
tuple.alive? && template.match(tuple)
end
end Находит живой кортеж, который соответствует template.
# 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 Находит все живые кортежи, которые соответствуют template.
# File lib/rinda/tuplespace.rb, line 372
def find_all_template(tuple)
@enum.find_all do |template|
template.alive? && template.match(tuple)
end
end Находит все кортежи в TupleBag, которые, рассматриваемые как шаблоны, соответствуют tuple и являются живыми.
# File lib/rinda/tuplespace.rb, line 324
def has_expires?
@enum.find do |tuple|
tuple.expires
end
end true если TupleBag содержит истекшие записи.
# File lib/rinda/tuplespace.rb, line 333 def push(tuple) key = bin_key(tuple) @hash[key] ||= TupleBin.new @hash[key].add(tuple) end
Добавляет tuple в TupleBag.
Приватные методы экземпляров
# File lib/rinda/tuplespace.rb, line 413 def bin_for_find(template) key = bin_key(template) key ? @hash.fetch(key, []) : @enum end
# File lib/rinda/tuplespace.rb, line 404
def bin_key(tuple)
head = tuple[0]
if head.class == Symbol
return head
else
false
end
end # File lib/rinda/tuplespace.rb, line 398
def each_entry(&blk)
@hash.each do |k, v|
v.each(&blk)
end
end
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.