lib/pione/patch/rinda-patch.rb in pione-0.1.2 vs lib/pione/patch/rinda-patch.rb in pione-0.1.3
- old
+ new
@@ -125,21 +125,18 @@
# Creates a new bin.
def initialize
@bin = {}
end
- # Adds the tuple.
+ # Add the tuple into the tuple space.
+ #
# @param [Array] tuple
# the tuple
# @return [void]
def add(tuple)
if dom = domain(tuple)
- unless @bin[dom]
- @bin[dom] = tuple
- else
- raise RedundantTupleError.new(tuple.value)
- end
+ @bin[dom] = tuple
else
raise RuntimeError
end
end
@@ -525,11 +522,11 @@
@bag.set_special_bin(
:task => TupleBag::DomainTupleBin,
:finished => TupleBag::DomainTupleBin,
:working => TupleBag::DomainTupleBin,
:data => TupleBag::DataTupleBin,
- :shift => TupleBag::HashTupleBin
+ :lift => TupleBag::HashTupleBin
)
@mutex = Mutex.new
end
def write(tuple, *args)
@@ -540,16 +537,16 @@
def move(port, tuple, sec=nil)
real_move(port, tuple, sec)
end
def read(tuple, sec=nil)
- shift_tuple(real_read(tuple, sec))
+ lift_tuple(real_read(tuple, sec))
end
def read_all(tuple)
real_read_all(tuple).map do |res|
- shift_tuple(res)
+ lift_tuple(res)
end
end
# Returns all tuples in the space.
# @param [Symbol] target
@@ -728,31 +725,42 @@
keep_clean
end
end
end
- def shift_tuple(tuple)
+ # Lift the location of the tuple.
+ #
+ # @param tuple [BasicTuple]
+ # tuple
+ # @return [BasicTuple]
+ # lifted tuple
+ def lift_tuple(tuple)
if Pione::Tuple[tuple.first]
- if pos = Pione::Tuple[tuple.first].uri_position
- if new_uri = shift_uri(tuple[pos])
+ if pos = Pione::Tuple[tuple.first].location_position
+ if new_location = lift_location(tuple[pos])
tuple = tuple.clone
- tuple[pos] = new_uri
+ tuple[pos] = new_location
end
end
end
return tuple
end
- def shift_uri(uri, old=[])
- return nil if old.include?(uri)
+ # Lift the location.
+ #
+ # @param location [Location::BasicLocation]
+ # location that lift from
+ # @param history [Array<Location::BasicLocation>]
+ # history of lifted location
+ # @return [Location::BasicLocation or nil]
+ # new location
+ def lift_location(location, history=[])
+ return nil if history.include?(location)
- template = TemplateEntry.new([:shift, uri, nil])
- if shift_tuple = @bag.find(template)
- next_uri = shift_tuple[2]
- if last_uri = shift_uri(next_uri, old + [uri])
- next_uri = last_uri
- end
- return next_uri
+ template = TemplateEntry.new([:lift, location, nil])
+ if lift_tuple = @bag.find(template)
+ new_location = lift_tuple[2]
+ return lift_location(new_location, history << location) || new_location
end
return nil
end
end
end