Rinda::TupleBag
class Rinda::TupleBag
Parent:Object
TupleBag是元组的无序集合。它是元组空间的基础。
公共实例方法
delete(tuple) 显示源
tuple
从TupleBag中移除。
# File lib/rinda/tuplespace.rb, line 341
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
delete_unless_alive() 显示源
从TupleBag中删除元组中的哪些死元组,返回删除的元组。
# File lib/rinda/tuplespace.rb, line 381
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
find(template) 显示源
查找匹配的活动元组template
。
# File lib/rinda/tuplespace.rb, line 361
def find(template)
bin_for_find(template).find do |tuple|
tuple.alive? && template.match(tuple)
end
end
find_all(template) 显示源
查找所有匹配的活动元组template
。
# File lib/rinda/tuplespace.rb, line 352
def find_all(template)
bin_for_find(template).find_all do |tuple|
tuple.alive? && template.match(tuple)
end
end
find_all_template(tuple)显示源
查找TupleBag中的所有元组,当这些元组被视为模板时,匹配tuple
并存活。
# File lib/rinda/tuplespace.rb, line 371
def find_all_template(tuple)
@enum.find_all do |template|
template.alive? && template.match(tuple)
end
end
has_expires?()显示源
true
如果TupleBag查看它是否有任何过期的条目。
# File lib/rinda/tuplespace.rb, line 323
def has_expires?
@enum.find do |tuple|
tuple.expires
end
end
push(tuple) 显示源
添加tuple
到TupleBag。
# File lib/rinda/tuplespace.rb, line 332
def push(tuple)
key = bin_key(tuple)
@hash[key] ||= TupleBin.new
@hash[key].add(tuple)
end
私有实例方法
bin_for_find(template)显示源
# File lib/rinda/tuplespace.rb, line 412
def bin_for_find(template)
key = bin_key(template)
key ? @hash.fetch(key, []) : @enum
end
bin_key(tuple) 显示源
# File lib/rinda/tuplespace.rb, line 403
def bin_key(tuple)
head = tuple[0]
if head.class == Symbol
return head
else
false
end
end
each_entry(&blk)显示源
# File lib/rinda/tuplespace.rb, line 397
def each_entry(&blk)
@hash.each do |k, v|
v.each(&blk)
end
end