class DpStmMap::AtomicView

Public Class Methods

new(global_state) click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 21
def initialize global_state
  @global_state=global_state
  @local_state={}
  @to_delete=Set.new
end

Public Instance Methods

[](key) click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 35
def [] key
  if @local_state.has_key? key
    @local_state[key]
  else
    @local_state[key]=@global_state[key]
  end
end
[]=(key, value) click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 27
def []= key, value
  if value == nil
    delete key
  else
    @local_state[key]=value
  end
end
changes() click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 59
def changes
  changes={}
  @local_state.each do |k,v|
    changes[k]=[@global_state[k],v]
  end
  @to_delete.each do |k|
    changes[k]=[@global_state[k],nil]
  end
  changes
end
commit() click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 70
def commit
  @to_delete.each do |key|
    @global_state.delete key
  end
  @global_state.merge!(@local_state)
end
delete(key) click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 51
def delete key
  if @local_state.has_key? key
    @local_state.delete key
  else
    @to_delete << key
  end
end
has_key?(key) click to toggle source
# File lib/dp_stm_map/InMemoryStmMap.rb, line 43
def has_key? key
  if @local_state.has_key?(key)
    @local_state[key] != @global_state[key]
  else        
    (not @to_delete.include?(key)) && @global_state.has_key?(key)
  end
end