class Concurrent::Collection::NonConcurrentMapBackend

@!visibility private

Public Class Methods

new(options = nil) click to toggle source

WARNING: all public methods of the class must operate on the @backend directly without calling each other. This is important because of the SynchronizedMapBackend which uses a non-reentrant mutex for performance reasons.

# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 15
def initialize(options = nil)
  @backend = {}
end

Public Instance Methods

[](key) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 19
def [](key)
  @backend[key]
end
Also aliased as: _get
[]=(key, value) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 23
def []=(key, value)
  @backend[key] = value
end
Also aliased as: _set
clear() click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 92
def clear
  @backend.clear
  self
end
compute(key) { |backend| ... } click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 57
def compute(key)
  store_computed_value(key, yield(@backend[key]))
end
compute_if_absent(key) { || ... } click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 27
def compute_if_absent(key)
  if NULL != (stored_value = @backend.fetch(key, NULL))
    stored_value
  else
    @backend[key] = yield
  end
end
compute_if_present(key) { |stored_value| ... } click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 51
def compute_if_present(key)
  if NULL != (stored_value = @backend.fetch(key, NULL))
    store_computed_value(key, yield(stored_value))
  end
end
delete(key) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 79
def delete(key)
  @backend.delete(key)
end
delete_pair(key, value) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 83
def delete_pair(key, value)
  if pair?(key, value)
    @backend.delete(key)
    true
  else
    false
  end
end
each_pair() { |k, v| ... } click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 97
def each_pair
  dupped_backend.each_pair do |k, v|
    yield k, v
  end
  self
end
get_and_set(key, value) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 69
def get_and_set(key, value)
  stored_value = @backend[key]
  @backend[key] = value
  stored_value
end
get_or_default(key, default_value) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 108
def get_or_default(key, default_value)
  @backend.fetch(key, default_value)
end
key?(key) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 75
def key?(key)
  @backend.key?(key)
end
merge_pair(key, value) { |stored_value| ... } click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 61
def merge_pair(key, value)
  if NULL == (stored_value = @backend.fetch(key, NULL))
    @backend[key] = value
  else
    store_computed_value(key, yield(stored_value))
  end
end
replace_if_exists(key, new_value) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 44
def replace_if_exists(key, new_value)
  if NULL != (stored_value = @backend.fetch(key, NULL))
    @backend[key] = new_value
    stored_value
  end
end
replace_pair(key, old_value, new_value) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 35
def replace_pair(key, old_value, new_value)
  if pair?(key, old_value)
    @backend[key] = new_value
    true
  else
    false
  end
end
size() click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 104
def size
  @backend.size
end

Private Instance Methods

_get(key)
Alias for: []
_set(key, value)
Alias for: []=
dupped_backend() click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 122
def dupped_backend
  @backend.dup
end
initialize_copy(other) click to toggle source
Calls superclass method
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 116
def initialize_copy(other)
  super
  @backend = {}
  self
end
pair?(key, expected_value) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 126
def pair?(key, expected_value)
  NULL != (stored_value = @backend.fetch(key, NULL)) && expected_value.equal?(stored_value)
end
store_computed_value(key, new_value) click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 130
def store_computed_value(key, new_value)
  if new_value.nil?
    @backend.delete(key)
    nil
  else
    @backend[key] = new_value
  end
end