Class: Concurrent::Collection::NonConcurrentMapBackend
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb |
Class Method Summary
-
.new(options = nil, &default_proc) ⇒ NonConcurrentMapBackend
constructor
WARNING: all public methods of the class must operate on the @backend directly without calling each other.
Instance Method Summary
- #[](key)
- #[]=(key, value)
- #clear
- #compute(key)
- #compute_if_absent(key)
- #compute_if_present(key)
- #delete(key)
- #delete_pair(key, value)
- #each_pair
- #get_and_set(key, value)
- #get_or_default(key, default_value)
- #key?(key) ⇒ Boolean
- #merge_pair(key, value)
- #replace_if_exists(key, new_value)
- #replace_pair(key, old_value, new_value)
- #size
- #dupped_backend private
- #initialize_copy(other) private
- #pair?(key, expected_value) ⇒ Boolean private
- #set_backend(default_proc) private
- #store_computed_value(key, new_value) private
Constructor Details
.new(options = nil, &default_proc) ⇒ NonConcurrentMapBackend
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( = nil, &default_proc) ( ) if .kind_of?(::Hash) set_backend(default_proc) @default_proc = default_proc end
Instance Method Details
#[](key)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb', line 21
def [](key) @backend[key] end
#[]=(key, value)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb', line 25
def []=(key, value) @backend[key] = value end
#clear
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb', line 94
def clear @backend.clear self end
#compute(key)
[ GitHub ]# 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)
[ GitHub ]#compute_if_present(key)
[ GitHub ]# 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)
[ GitHub ]# 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)
[ GitHub ]#dupped_backend (private)
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb', line 130
def dupped_backend @backend.dup end
#each_pair
[ GitHub ]# 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)
[ GitHub ]# 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)
[ GitHub ]# 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
#initialize_copy(other) (private)
[ GitHub ]# 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
#key?(key) ⇒ Boolean
# 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)
[ GitHub ]# 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
#pair?(key, expected_value) ⇒ Boolean
(private)
#replace_if_exists(key, new_value)
[ GitHub ]#replace_pair(key, old_value, new_value)
[ GitHub ]# 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
#set_backend(default_proc) (private)
[ GitHub ]#size
[ GitHub ]# File 'lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb', line 106
def size @backend.size end
#store_computed_value(key, new_value) (private)
[ GitHub ]# 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