class Concurrent::Collection::NonConcurrentMapBackend
@!visibility private
Public Class Methods
new(options = nil, &default_proc)
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, &default_proc) validate_options_hash!(options) if options.kind_of?(::Hash) set_backend(default_proc) @default_proc = default_proc end
Public Instance Methods
[](key)
click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 21 def [](key) @backend[key] end
[]=(key, value)
click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 25 def []=(key, value) @backend[key] = value end
clear()
click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 94 def clear @backend.clear self end
compute(key) { |get_or_default(key, nil)| ... }
click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 59 def compute(key) store_computed_value(key, yield(get_or_default(key, nil))) end
compute_if_absent(key) { || ... }
click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 29 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 53 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 81 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 85 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 99 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 71 def get_and_set(key, value) stored_value = get_or_default(key, nil) @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 110 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 77 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 63 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 46 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 37 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 106 def size @backend.size end
Private Instance Methods
dupped_backend()
click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 130 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 124 def initialize_copy(other) super set_backend(@default_proc) self end
pair?(key, expected_value)
click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 134 def pair?(key, expected_value) NULL != (stored_value = @backend.fetch(key, NULL)) && expected_value.equal?(stored_value) end
set_backend(default_proc)
click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 116 def set_backend(default_proc) if default_proc @backend = ::Hash.new { |_h, key| default_proc.call(self, key) } else @backend = {} end end
store_computed_value(key, new_value)
click to toggle source
# File lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb, line 138 def store_computed_value(key, new_value) if new_value.nil? @backend.delete(key) nil else @backend[key] = new_value end end