class Concurrent::Map
Experimental RBS support (using type sampling data from the type_fusion project).
# sig/concurrent-ruby/concurrent/map.rbs class Concurrent::Map < Concurrent::Collection::MapImplementation type Concurrent__Map_[]_key = String | Symbol | Integer | Thread | Array[] | Array[Symbol] | nil | Hash type Concurrent__Map_[]_return_value = ActiveRecord::ConnectionAdapters::PoolManager | ActiveSupport::Inflector::Inflections | String | Concurrent::Map | ActiveRecord::ConnectionAdapters::PostgreSQLAdapter | nil | ActionView::Template | ActionView::TemplateDetails::Requested | AASM::Base | AASM::StateMachine | AASM::StateMachineStore | ActiveRecord::ConnectionAdapters::SQLite3Adapter | Array[ActiveSupport::Notifications::Fanout::Subscribers::Evented] | Array[] | Array[Symbol] | bool def []: (Concurrent__Map_[]_key key) -> Concurrent__Map_[]_return_value def each_pair: () -> Concurrent::Map def each_value: () -> Concurrent::Map type Concurrent__Map_fetch_key = Array[Integer] | String | Class | Sprockets::DirectiveProcessor | Sprockets::Preprocessors::DefaultSourceMap | Array[] | Integer | Hash type Concurrent__Map_fetch_return_value = ActiveModel::Type::String | nil | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb | File::Stat | String | Sprockets::Asset | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp | ActiveModel::Type::Integer | Concurrent::Map | ActiveModel::Type::Boolean | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TimestampWithTimeZone | ActiveModel::Type::Float | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Interval | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Inet | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Date | ActiveRecord::Type::Text | ActionView::TemplateDetails::Requested | ActiveRecord::Type::DateTime | Array[String] | Array[NilClass] | ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer | Array[] def fetch: (Concurrent__Map_fetch_key key, ?Object default_value) -> Concurrent__Map_fetch_return_value type Concurrent__Map_fetch_or_store_key = Array[Integer] | String | Sprockets::Preprocessors::DefaultSourceMap | Class | Sprockets::DirectiveProcessor | Integer | Array[] type Concurrent__Map_fetch_or_store_return_value = ActiveModel::Type::String | nil | File::Stat | String | Sprockets::Asset | ActiveModel::Type::Integer | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp | Concurrent::Map | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb | ActiveRecord::Type::Text | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TimestampWithTimeZone | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Date | ActiveModel::Type::Boolean | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Inet | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array | ActiveRecord::Type::DateTime | ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer | Array[String] | Array[NilClass] | Array[] def fetch_or_store: (Concurrent__Map_fetch_or_store_key key, ?(Object | Concurrent::Map) default_value) -> Concurrent__Map_fetch_or_store_return_value def initialize: (?Hash? options, ) -> void def inspect: () -> String def keys: () -> untyped def validate_options_hash!: (Hash options) -> nil def values: () -> untyped end
‘Concurrent::Map` instead of `Concurrent::Hash` for your concurrency-safe hash needs.
does. For most uses it should do fine though, and we recommend you consider
– for instance, it does not necessarily retain ordering by insertion time as `Hash`
However, `Concurrent::Map `is not strictly semantically equivalent to a ruby `Hash`
characteristics, especially under high concurrency, than `Concurrent::Hash`.
`Concurrent::Map` is a hash-like object and should have much better performance
def [](key)
Experimental RBS support (using type sampling data from the type_fusion project).
type Concurrent__Map_[]_key = String | Symbol | Integer | Thread | Array[] | Array[Symbol] | nil | Hash type Concurrent__Map_[]_return_value = ActiveRecord::ConnectionAdapters::PoolManager | ActiveSupport::Inflector::Inflections | String | Concurrent::Map | ActiveRecord::ConnectionAdapters::PostgreSQLAdapter | nil | ActionView::Template | ActionView::TemplateDetails::Requested | AASM::Base | AASM::StateMachine | AASM::StateMachineStore | ActiveRecord::ConnectionAdapters::SQLite3Adapter | Array[ActiveSupport::Notifications::Fanout::Subscribers::Evented] | Array[] | Array[Symbol] | bool type Concurrent__Map_[]_key = String | Symbol | Integer | Thread | | nil | locale | | formats | | variants | | handlers | Symbol | Symbol | Symbol | Symbol | Symbol | locale | | formats | Symbol | variants | | handlers | Symbol | Symbol | Symbol | Symbol | Symbol | Symbol | Symbol type Concurrent__Map_[]_return_value = ActiveRecord::ConnectionAdapters::PoolManager | ActiveSupport::Inflector::Inflections | String | Concurrent::Map | ActiveRecord::ConnectionAdapters::PostgreSQLAdapter | nil | ActionView::Template | ActionView::TemplateDetails::Requested | AASM::Base | AASM::StateMachine | AASM::StateMachineStore | ActiveRecord::ConnectionAdapters::SQLite3Adapter | ActiveSupport::Notifications::Fanout::Subscribers::Evented | ActiveSupport::Notifications::Fanout::Subscribers::EventObject | ActiveSupport::Notifications::Fanout::Subscribers::EventObject | | Symbol | Symbol | bool def []: (Concurrent__Map_[]_key key) -> Concurrent__Map_[]_return_value
This signature was generated using 2742 samples from 8 applications.
-
(Object)- the value
Parameters:
-
key(Object) --
def [](key) if value = super # non-falsy value is an existing mapping, return it right away value # re-check is done with get_or_default(key, NULL) instead of a simple !key?(key) in order to avoid a race condition, whereby by the time the current thread gets to the key?(key) call # a key => value mapping might have already been created by a different thread (key?(key) would then return true, this elsif branch wouldn't be taken and an incorrent +nil+ value # would be returned) # note: nil == value check is not technically necessary elsif @default_proc && nil == value && NULL == (value = get_or_default(key, NULL)) @default_proc.call(self, key) else value end end
def each_key
-
(self)-
Other tags:
- Yieldparam: key -
Other tags:
- Yield: - for each key in the map
def each_key each_pair { |k, v| yield k } end unless method_defined?(:each_key)
def each_pair
Experimental RBS support (using type sampling data from the type_fusion project).
def each_pair: () -> Concurrent::Map
This signature was generated using 152 samples from 2 applications.
-
(self)-
Other tags:
- Yieldparam: value -
Yieldparam: key -
Other tags:
- Yield: - for each key value pair in the map
def each_pair return enum_for :each_pair unless block_given? super end
def each_value
Experimental RBS support (using type sampling data from the type_fusion project).
def each_value: () -> Concurrent::Map
This signature was generated using 12 samples from 2 applications.
-
(self)-
Other tags:
- Yieldparam: value -
Other tags:
- Yield: - for each value in the map
def each_value each_pair { |k, v| yield v } end unless method_defined?(:each_value)
def empty?
-
(true, false)-
def empty? each_pair { |k, v| return false } true end unless method_defined?(:empty?)
def fetch(key, default_value = NULL)
Experimental RBS support (using type sampling data from the type_fusion project).
type Concurrent__Map_fetch_key = Array[Integer] | String | Class | Sprockets::DirectiveProcessor | Sprockets::Preprocessors::DefaultSourceMap | Array[] | Integer | Hash type Concurrent__Map_fetch_return_value = ActiveModel::Type::String | nil | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb | File::Stat | String | Sprockets::Asset | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp | ActiveModel::Type::Integer | Concurrent::Map | ActiveModel::Type::Boolean | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TimestampWithTimeZone | ActiveModel::Type::Float | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Interval | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Inet | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Date | ActiveRecord::Type::Text | ActionView::TemplateDetails::Requested | ActiveRecord::Type::DateTime | Array[String] | Array[NilClass] | ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer | Array[] type Concurrent__Map_fetch_key = String | String | Class | Sprockets::DirectiveProcessor | Sprockets::Preprocessors::DefaultSourceMap | | Integer | locale | | formats | | variants | | handlers | Symbol | Symbol | Symbol | Symbol | Symbol type Concurrent__Map_fetch_return_value = ActiveModel::Type::String | nil | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb | File::Stat | String | Sprockets::Asset | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp | ActiveModel::Type::Integer | Concurrent::Map | ActiveModel::Type::Boolean | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TimestampWithTimeZone | ActiveModel::Type::Float | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Interval | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Inet | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Date | ActiveRecord::Type::Text | ActionView::TemplateDetails::Requested | ActiveRecord::Type::DateTime | | String | String | String | String | String | String | String | String | String | String | String | String | String | String | String | ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer def fetch: (Concurrent__Map_fetch_key key, ?Object default_value) -> Concurrent__Map_fetch_return_value
This signature was generated using 766 samples from 6 applications.
- Note: - The "fetch-then-act" methods of `Map` are not atomic. `Map` is intended
Raises:
-
(KeyError)- when key is missing and no default_value is provided
Returns:
-
(Object)- the value or default value
Other tags:
- Yieldreturn: - default value
Other tags:
- Yieldparam: key -
Other tags:
- Yield: - default value for a key
Parameters:
-
default_value(Object) -- -
key(Object) --
def fetch(key, default_value = NULL) if NULL != (value = get_or_default(key, NULL)) value elsif block_given? yield key elsif NULL != default_value default_value else raise_fetch_no_key end end
def fetch_or_store(key, default_value = NULL)
Experimental RBS support (using type sampling data from the type_fusion project).
type Concurrent__Map_fetch_or_store_key = Array[Integer] | String | Sprockets::Preprocessors::DefaultSourceMap | Class | Sprockets::DirectiveProcessor | Integer | Array[] type Concurrent__Map_fetch_or_store_return_value = ActiveModel::Type::String | nil | File::Stat | String | Sprockets::Asset | ActiveModel::Type::Integer | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp | Concurrent::Map | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb | ActiveRecord::Type::Text | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TimestampWithTimeZone | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Date | ActiveModel::Type::Boolean | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Inet | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array | ActiveRecord::Type::DateTime | ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer | Array[String] | Array[NilClass] | Array[] type Concurrent__Map_fetch_or_store_key = String | String | Sprockets::Preprocessors::DefaultSourceMap | Class | Sprockets::DirectiveProcessor | Integer | type Concurrent__Map_fetch_or_store_return_value = ActiveModel::Type::String | nil | File::Stat | String | Sprockets::Asset | ActiveModel::Type::Integer | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp | Concurrent::Map | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb | ActiveRecord::Type::Text | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TimestampWithTimeZone | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Date | ActiveModel::Type::Boolean | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Inet | ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array | ActiveRecord::Type::DateTime | ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer | | NilClass | NilClass | NilClass | String | String def fetch_or_store: (Concurrent__Map_fetch_or_store_key key, ?(Object | Concurrent::Map) default_value) -> Concurrent__Map_fetch_or_store_return_value
This signature was generated using 809 samples from 6 applications.
-
(Object)- the value or default value
Other tags:
- Yieldreturn: - default value
Other tags:
- Yieldparam: key -
Other tags:
- Yield: - default value for a key
Parameters:
-
default_value(Object) -- -
key(Object) --
def fetch_or_store(key, default_value = NULL) fetch(key) do put(key, block_given? ? yield(key) : (NULL == default_value ? raise_fetch_no_key : default_value)) end end
def initialize(options = nil, &default_proc)
Experimental RBS support (using type sampling data from the type_fusion project).
def initialize: (?[["initial_capacity", "Integer"]]? options, ) -> void
This signature was generated using 93 samples from 5 applications.
-
default_proc(Proc) -- Optional block to compute the default value if the key is not set, like `Hash#default_proc` -
options(Hash, nil) -- options to set the :initial_capacity or :load_factor. Ignored on some Rubies.
def initialize(options = nil, &default_proc) if options.kind_of?(::Hash) validate_options_hash!(options) else options = nil end super(options) @default_proc = default_proc end
def initialize_copy(other)
def initialize_copy(other) super populate_from(other) end
def inspect
Experimental RBS support (using type sampling data from the type_fusion project).
def inspect: () -> String
This signature was generated using 1 sample from 1 application.
def inspect format '%s entries=%d default_proc=%s>', to_s[0..-2], size.to_s, @default_proc.inspect end
def key(value)
-
(Object, nil)- key or nil when not found
Parameters:
-
value(Object) --
def key(value) each_pair { |k, v| return k if v == value } nil end unless method_defined?(:key)
def keys
Experimental RBS support (using type sampling data from the type_fusion project).
def keys: () -> untyped
This signature was generated using 11 samples from 1 application.
-
(::Array- keys
def keys arr = [] each_pair { |k, v| arr << k } arr end unless method_defined?(:keys)
def marshal_dump
def marshal_dump raise TypeError, "can't dump hash with default proc" if @default_proc h = {} each_pair { |k, v| h[k] = v } h end
def marshal_load(hash)
def marshal_load(hash) initialize populate_from(hash) end
def populate_from(hash)
def populate_from(hash) hash.each_pair { |k, v| self[k] = v } self end
def put_if_absent(key, value)
-
(Object, nil)- the previous value when key was present or nil when there was no key
Parameters:
-
value(Object) -- -
key(Object) --
def put_if_absent(key, value) computed = false result = compute_if_absent(key) do computed = true value end computed ? nil : result end unless method_defined?(:put_if_absent)
def raise_fetch_no_key
def raise_fetch_no_key raise KeyError, 'key not found' end
def size
-
(Integer)- size
def size count = 0 each_pair { |k, v| count += 1 } count end unless method_defined?(:size)
def validate_options_hash!(options)
Experimental RBS support (using type sampling data from the type_fusion project).
def validate_options_hash!: (initial_capacity | Integer options) -> nil
This signature was generated using 8 samples from 3 applications.
def validate_options_hash!(options) if (initial_capacity = options[:initial_capacity]) && (!initial_capacity.kind_of?(Integer) || initial_capacity < 0) raise ArgumentError, ":initial_capacity must be a positive Integer" end if (load_factor = options[:load_factor]) && (!load_factor.kind_of?(Numeric) || load_factor <= 0 || load_factor > 1) raise ArgumentError, ":load_factor must be a number between 0 and 1" end end
def value?(value)
-
(true, false)-
Parameters:
-
value(Object) --
def value?(value) each_value do |v| return true if value.equal?(v) end false end
def values
Experimental RBS support (using type sampling data from the type_fusion project).
def values: () -> untyped
This signature was generated using 49 samples from 1 application.
-
(::Array- values
def values arr = [] each_pair { |k, v| arr << v } arr end unless method_defined?(:values)