xtd 1.0.0
Loading...
Searching...
No Matches
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t > Class Template Reference
Inheritance diagram for xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >:
xtd::object xtd::collections::generic::idictionary< key_t, value_t > xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > > xtd::collections::generic::ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > > xtd::collections::generic::extensions::collection_common< xtd::collections::generic::key_value_pair< key_t, value_t >, icollection< xtd::collections::generic::key_value_pair< key_t, value_t > > > xtd::interface xtd::collections::generic::ienumerable_abstract xtd::collections::generic::extensions::enumerable_iterators< xtd::collections::generic::key_value_pair< key_t, value_t >, xtd::collections::generic::ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > > > xtd::collections::generic::extensions::enumerable< xtd::collections::generic::key_value_pair< key_t, value_t >, xtd::collections::generic::ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > > >

Definition

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
class xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >

Represents a thread-safe collection of key/value pairs that can be accessed by multiple threads concurrently.

Definition
template<typename type_t>
Represents a thread-safe collection of key/value pairs that can be accessed by multiple threads concu...
Definition concurrent_dictionary.hpp:37
concurrent_dictionary()=default
Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:40
Header
#include <xtd/collections/concurrent/concurrent_dictionary>
Namespace
xtd::collections::concurrent
Library
xtd.core
Examples
The following example shows how to construct a xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> object.
#include <xtd/xtd>
class example {
public:
// Demonstrates:
// concurrent_dictionary<key_t, value_t> ctor(concurrency_level, initial_capacity)
// concurrent_dictionary<key_t, value_t>[key_t]
static auto main() {
// We know how many items we want to insert into the ConcurrentDictionary.
// So set the initial capacity to some prime number above that, to ensure that
// the ConcurrentDictionary does not need to be resized while initializing it.
auto HIGHNUMBER = 64;
auto initial_capacity = 101_z;
// The higher the concurrencyLevel, the higher the theoretical number of operations
// that could be performed concurrently on the concurrent_dictionary. However, global
// operations like resizing the dictionary take longer as the concurrencyLevel rises.
// For the purposes of this example, we'll compromise at num_procs * 2.
auto num_procs = environment::processor_count();
auto concurrency_level = num_procs * 2;
// Construct the dictionary with the desired concurrencyLevel and initial_capacity
auto cd = concurrent_dictionary<int, int>(concurrency_level, initial_capacity);
// Initialize the dictionary
for (auto i = 1; i <= HIGHNUMBER; ++i)
cd[i] = i * i;
console::write_line("The square of 23 is {} (should be {})", cd[23], 23 * 23);
}
};
startup_(example::main);
// This code produces the following output :
//
// The square of 23 is 529 (should be 529)
static auto write_line() -> void
Writes the current line terminator to the standard output stream using the specified format informati...
static auto processor_count() -> xtd::usize
Gets the number of processors on the current machine.
#define startup_(...)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:152
@ i
The I key.
Definition console_key.hpp:104
Provides several thread-safe collection classes that should be used in place of the corresponding typ...
Definition concurrent_bag.hpp:20

Public Aliases

using key_type
 Represents the dictionary key type.
using mapped_type
 Represents the dictionary mapped type.
using value_type
 Represents the dictionary value type.
using reference
 Represents the reference of list value type.
using const_reference
 Represents the const reference of list value type.
using collection_type
 Represents the concurrent bag collection type.
using key_collection
 Represents the idictionary key collection type.
using value_collection
 Represents the idictionary value collection type.

Public Conctructors

 concurrent_dictionary ()=default
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that is empty, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.
 concurrent_dictionary (xtd::collections::generic::ienumerable< value_type > &&collection)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::collections::generic::ienumerable<value_type>, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.
 concurrent_dictionary (xtd::iterable auto &&collection)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::iterable, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.
 concurrent_dictionary (const xtd::collections::generic::iequality_comparer< key_type > &comparercomparer)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that is empty, has the default concurrency level and capacity, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.
 concurrent_dictionary (xtd::collections::generic::ienumerable< value_type > &&collection, const xtd::collections::generic::iequality_comparer< key_type > &comparercomparer)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::collections::generic::ienumerable has the default concurrency level, has the default initial capacity, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.
 concurrent_dictionary (xtd::iterable auto &&collection, const xtd::collections::generic::iequality_comparer< key_type > &comparercomparer)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::iterable has the default concurrency level, has the default initial capacity, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.
 concurrent_dictionary (xtd::usize concurrent_level, xtd::usize capacity)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that is empty, has the specified concurrency level and capacity, and uses the default comparer for the key type.
 concurrent_dictionary (xtd::usize concurrent_level, xtd::collections::generic::ienumerable< value_type > &&collection, const xtd::collections::generic::iequality_comparer< key_type > &comparercomparer)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::collections::generic::ienumerable, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.
 concurrent_dictionary (xtd::usize concurrent_level, xtd::iterable auto &&collection, const xtd::collections::generic::iequality_comparer< key_type > &comparercomparer)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::iterable, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.
 concurrent_dictionary (xtd::usize concurrent_level, xtd::usize capacity, const xtd::collections::generic::iequality_comparer< key_type > &comparercomparer)
 Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that is empty, has the specified concurrency level and capacity, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.
 concurrent_dictionary (std::initializer_list< std::pair< key_t, value_t > > items)
 Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a variety of data sources.
 concurrent_dictionary (std::initializer_list< value_type > items)
 Constructs the container with the contents of the specified initializer list, and allocator.

Public Properties

auto comparer () const noexcept -> const xtd::collections::generic::iequality_comparer< key_t > &
 Gets the xtd::collections::generic::iequality_comparer <type_t> that is used to determine equality of keys for the dictionary.
auto count () const noexcept -> xtd::usize override
 Gets the number of elements contained in the xtd::collections::generic::icollection.
auto is_empty () const noexcept -> bool
 Gets a value that indicates whether the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is empty.
auto is_read_only () const noexcept -> bool override
 Gets a value indicating whether the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is read-only.
auto is_synchronized () const noexcept -> bool override
 Gets a value indicating whether access to the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is synchronized (thread safe).
auto keys () const noexcept -> key_collection override
 Gets a collection containing the keys in the xtd::collections::generic::ictionary<key_t,value_t>.
auto values () const noexcept -> value_collection override
 Gets a collection that contains the values in the xtd::collections::generic::ictionary<key_t,value_t>.

Public Methods

auto add_or_update (const key_t &key, xtd::callable< value_t, key_t > auto &&add_value_factory, xtd::callable< value_t, key_t, value_t > auto &&update_value_factory) -> const value_t &
 Uses the specified functions to add a key/value pair to the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key does not already exist, or to update a key/value pair in the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key already exists.
auto add_or_update (const key_t &key, const value_t &add_value, xtd::callable< value_t, key_t, value_t > auto &&update_value_factory) -> const value_t &
 Adds a key/value pair to the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key does not already exist, or updates a key/value pair in the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> by using the specified function if the key already exists.
template<typename arg_t>
auto add_or_update (const key_t &key, xtd::callable< value_t, key_t, arg_t > auto &&add_value_factory, xtd::callable< value_t, key_t, value_t, arg_t > auto &&update_value_factory, arg_t &&factory_argument) -> const value_t &
 Uses the specified functions and argument to add a key/value pair to the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key does not already exist, or to update a key/value pair in the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key already exists.
auto clear () -> void override
 Removes all keys and values from the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.
auto contains_key (const key_t &key) const noexcept -> bool override
 Determines whether the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> contains the specified key.
auto copy_to (xtd::array< value_type > &array, xtd::usize array_index) const -> void override
 Copies the elements of the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> to an xtd::array, starting at a particular xtd::array index.
auto get_enumerator () const -> xtd::collections::generic::enumerator< value_type > override
 Returns an enumerator that iterates through a collection.
auto get_or_add (const key_t &key, xtd::callable< value_t, key_t > auto &&add_value_factory) -> const value_t &
 Adds a key/value pair to the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> by using the specified function if the key does not already exist. Returns the new value, or the existing value if the key exists.
auto get_or_add (const key_t &key, const value_t &add_value) -> const value_t &
 Adds a key/value pair to the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> if the key does not already exist. Returns the new value, or the existing value if the key exists.
template<typename arg_t>
auto get_or_add (const key_t &key, xtd::callable< value_t, key_t, arg_t > auto &&add_value_factory, arg_t &&factory_argument) -> const value_t &
 Adds a key/value pair to the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> by using the specified function and an argument if the key does not already exist, or returns the existing value if the key exists.
auto to_array () const -> xtd::array< value_type >
 Copies the elements contained in the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> to a new array.
auto to_string () const noexcept -> xtd::string override
 Returns a xtd::string that represents the current object.
auto try_add (const key_t &key, const value_t &value) -> bool
 Attempts to add the specified key and value to the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.
auto try_get_value (const key_t &key, value_t &value) const -> bool override
 Attempts to get the value associated with the specified key from the xtd::collections::concurrent::concurrent_dictionary <key_t,value_t>.
auto try_remove (const key_t &key) -> bool
 Attempts to remove and return the value that has the specified key from the xtd::collections::concurrent::concurrent_dictionary <key_t,value_t>.
auto try_remove (const key_t &key, value_t &value) -> bool
 Attempts to remove and return the value that has the specified key from the xtd::collections::concurrent::concurrent_dictionary <key_t,value_t>.
auto try_remove (const xtd::collections::generic::key_value_pair< key_t, value_t > &item) -> bool
 Removes a key and value from the dictionary. @pram item The xtd::collections::generic::key_value_pair<key_t,value_t> representing the key and value to remove.
auto try_update (const key_t &key, const value_t &new_value, const value_t &comparison_value) -> bool
 Updates the value associated with key to new_value if the existing value with key is equal to comparison_value.

Public Operators

auto operator[] (const key_t &key) const -> const value_t &override
 Gets the element with the specified key.
auto operator[] (const key_t &key) -> value_t &override
 Sets the element with the specified key.

Additional Inherited Members

using key_type
 Represents the dictionary key type.
using mapped_type
 Represents the dictionary mapped type.
using value_type
 Represents the xtd::collections::generic::idictionary value type.
using iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
using const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
using key_collection
 Represents the idictionary key collection type.
using value_collection
 Represents the idictionary value collection type.
using value_type
 Represents the xtd::collections::generic::icollection value type.
using value_type
 Represents the xtd::collections::generic::ienumerable value type.
using iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
using const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
using iterator
 Represents the iterator of enumerable value type.
using const_iterator
 Represents the const iterator of enumerable value type.
using enumerable_type
 Represents the ienumerable enumerable type.
using value_type
 Represents the ienumerable value type.
using ienumerable
 Represents the ienumerable value type.
using list
 Represents the list value type.
 object ()=default
 Create a new instance of the ultimate base class object.
virtual auto equals (const object &obj) const noexcept -> bool
 Determines whether the specified object is equal to the current object.
virtual auto get_hash_code () const noexcept -> xtd::usize
 Serves as a hash function for a particular type.
virtual auto get_type () const noexcept -> type_object
 Gets the type of the current instance.
template<typename object_t>
auto memberwise_clone () const -> xtd::unique_ptr_object< object_t >
 Creates a shallow copy of the current object.
virtual auto copy_to (xtd::array< xtd::collections::generic::key_value_pair< key_t, value_t > > &array, xtd::usize array_index) const -> void=0
 Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array, starting at a particular xtd::array index.
auto begin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
auto cbegin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
auto cend () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
auto end () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
auto aggregate (auto &&funcfunc) const -> value_t
 Applies an accumulator function over a sequence.
auto all (predicate_t &&predicatepredicate) const -> bool
 Determines whether all elements of a sequence satisfy a condition.
auto any () const noexcept -> bool
 Determines whether a sequence contains any elements.
auto append (element_t &&element) const noexcept -> xtd::collections::generic::enumerable_generator< value_t >
 Appends a value to the end of the sequence.
auto as_enumerable () const noexcept
 Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
auto average () const noexcept
 Computes the average of a sequence of value_t values.
auto cast () const noexcept -> xtd::collections::generic::enumerable_generator< result_t >
 Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
auto chunk (xtd::usize size) const -> xtd::collections::generic::enumerable_generator< xtd::array< value_t > >
 Splits the elements of a sequence into chunks of size at most size.
auto concat (second_t &&second) const noexcept -> xtd::collections::generic::enumerable_generator< value_t >
 Concatenates two sequences.
auto contains (value_t &&value) const noexcept -> bool
 Determines whether a sequence contains a specified element by using the default equality comparer.
auto count () const noexcept -> xtd::usize
 Returns the number of elements in current sequence.
auto count_by (key_selector_t &&key_selector) const noexcept
 Returns the count of elements in the current sequence grouped by key.
auto default_if_empty () const noexcept -> xtd::collections::generic::enumerable_generator< value_t >
 Returns the elements of the specified sequence or the type parameter's default value in a singleton collection if the current sequence is empty.
auto distinct () const noexcept -> xtd::collections::generic::enumerable_generator< value_t >
 Returns distinct elements from a sequence by using the default equality comparer to compare values.
auto first () const -> value_t
 Returns the first element of a sequence.
auto first_or_default (predicate_t &&predicatepredicate, value_t &&default_value) const noexcept -> value_t
 Returns the first element of the sequence that satisfies a condition, or a specified default value if no such element is found.
auto last () const -> value_t
 Returns the last element of a sequence.
auto max () const -> value_t
 Returns the maximum value in a sequence of xtd::numeric values.
auto min () const -> value_t
 Returns the minimum value in a sequence of xtd::numeric values.
auto order () const -> xtd::collections::generic::enumerable_generator< value_t >
 Sorts the elements of a sequence in ascending order.
auto order_by (const std::function< value_t(const value_t &)> &key_selector) const
 Sorts the elements of a sequence in ascending order according to a key.
auto order_by_descending (const std::function< key_t(const value_t &)> &key_selector) const
 Sorts the elements of a sequence in descending order according to a key.
auto reverse () const -> xtd::collections::generic::enumerable_generator< value_t >
 Inverts the order of the elements in a sequence.
auto select (auto &&selector) const
 Projects each element of a sequence into a new form.
auto sequence_equal (second_t &&second) const -> bool
 Determines whether two sequences are equal by comparing the elements by using the default equality comparer for their type.
auto shuffle () const -> xtd::collections::generic::enumerable_generator< value_t >
 Shuffles the order of the elements of a sequence.
auto skip (xtd::usize count) const -> xtd::collections::generic::enumerable_generator< value_t >
 Bypasses a specified number of elements in a sequence and then returns the remaining elements.
auto skip_while (auto &&predicatepredicate) const -> xtd::collections::generic::enumerable_generator< value_t >
 Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.
auto take (xtd::usize count) const -> xtd::collections::generic::enumerable_generator< value_t >
 Returns a specified number of contiguous elements from the start of a sequence.
auto take_while (auto &&predicatepredicate) const -> xtd::collections::generic::enumerable_generator< value_t >
 Returns elements from a sequence as long as a specified condition is true, and then skips the remaining elements.
auto to_array () const -> xtd::array< value_t >
 Creates a xtd::array <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto to_list () const -> xtd::collections::generic::list< value_t >
 Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto where (auto &&predicatepredicate) const
 Filters a sequence of values based on a predicate.
auto zip (second_t &&second) const -> xtd::collections::generic::enumerable_generator< std::tuple< value_t, xtd::iterable_value_type< second_t > > >
 Produces a sequence of tuples with elements from the two specified sequences.
virtual auto empty () const noexcept -> bool
 Checks whether the container is empty.
virtual auto size () const noexcept -> xtd::usize
 Gets the number of elements contained in the xtd::collections::generic::icollection <type_t>.
virtual auto operator<< (const xtd::collections::generic::key_value_pair< key_t, value_t > &item) -> icollection< xtd::collections::generic::key_value_pair< key_t, value_t > > &
 The shift left operator adds an item to the xtd::collections::generic::icollection <type_t>.
virtual auto operator>> (const xtd::collections::generic::key_value_pair< key_t, value_t > &item) -> icollection< xtd::collections::generic::key_value_pair< key_t, value_t > > &
 The shift right operator removes the first occurrence of a specific object from the xtd::collections::generic::icollection <type_t>.
template<typename object_a_t, typename object_b_t>
static auto equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are considered equal.
template<typename object_a_t, typename object_b_t>
static auto reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are the same instance.
static auto to_const_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.
static auto to_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.

Member Typedef Documentation

◆ key_type

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
using xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::key_type

Represents the dictionary key type.

◆ mapped_type

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
using xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::mapped_type

Represents the dictionary mapped type.

◆ value_type

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
using xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::value_type

Represents the dictionary value type.

◆ reference

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
using xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::reference

Represents the reference of list value type.

◆ const_reference

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
using xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::const_reference

Represents the const reference of list value type.

◆ collection_type

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
using xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::collection_type

Represents the concurrent bag collection type.

◆ key_collection

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
using xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::key_collection

Represents the idictionary key collection type.

◆ value_collection

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
using xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::value_collection

Represents the idictionary value collection type.

Constructor & Destructor Documentation

◆ concurrent_dictionary() [1/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( )
default

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that is empty, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.

Remarks
The default concurrency level is equal to the number of CPUs. The higher the concurrency level is, the more concurrent write operations can take place without interference and blocking. Higher concurrency level values also cause operations that require all locks (for example, table resizing, ToArray and Count) to become more expensive. The default capacity (DEFAULT_CAPACITY), which represents the initial number of buckets, is a trade-off between the size of a very small dictionary and the number of resizes when constructing a large dictionary. Also, the capacity should not be divisible by a small prime number. The default capacity is 31.

◆ concurrent_dictionary() [2/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( xtd::collections::generic::ienumerable< value_type > && collection)
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::collections::generic::ienumerable<value_type>, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.

Parameters
collectionThe xtd::collections::generic::ienumerable<value_type> whose elements are copied to the new xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.

◆ concurrent_dictionary() [3/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( xtd::iterable auto && collection)
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::iterable, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.

Parameters
collectionThe xtd::iterable whose elements are copied to the new xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.

◆ concurrent_dictionary() [4/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( const xtd::collections::generic::iequality_comparer< key_type > & comparer)
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that is empty, has the default concurrency level and capacity, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.

Parameters
comparerThe equality comparison implementation to use when comparing keys.

◆ concurrent_dictionary() [5/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( xtd::collections::generic::ienumerable< value_type > && collection,
const xtd::collections::generic::iequality_comparer< key_type > & comparer )
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::collections::generic::ienumerable has the default concurrency level, has the default initial capacity, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.

Parameters
collectionThe xtd::collections::generic::ienumerable<value_type> whose elements are copied to the new xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.
comparerThe equality comparison implementation to use when comparing keys.

◆ concurrent_dictionary() [6/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( xtd::iterable auto && collection,
const xtd::collections::generic::iequality_comparer< key_type > & comparer )
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::iterable has the default concurrency level, has the default initial capacity, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.

Parameters
collectionThe xtd::iterable whose elements are copied to the new xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.
comparerThe equality comparison implementation to use when comparing keys.

◆ concurrent_dictionary() [7/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( xtd::usize concurrent_level,
xtd::usize capacity )
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that is empty, has the specified concurrency level and capacity, and uses the default comparer for the key type.

Parameters
concurrent_levelThe estimated number of threads that will update the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> concurrently,.
capacityThe initial number of elements that the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> can contain.

◆ concurrent_dictionary() [8/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( xtd::usize concurrent_level,
xtd::collections::generic::ienumerable< value_type > && collection,
const xtd::collections::generic::iequality_comparer< key_type > & comparer )
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::collections::generic::ienumerable, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.

Parameters
concurrent_levelThe estimated number of threads that will update the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> concurrently,.
collectionThe xtd::collections::generic::ienumerable<value_type> whose elements are copied to the new xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.
comparerThe equality comparison implementation to use when comparing keys.

◆ concurrent_dictionary() [9/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( xtd::usize concurrent_level,
xtd::iterable auto && collection,
const xtd::collections::generic::iequality_comparer< key_type > & comparer )
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that contains elements copied from the specified xtd::iterable, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.

Parameters
concurrent_levelThe estimated number of threads that will update the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> concurrently,.
collectionThe xtd::iterable whose elements are copied to the new xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.
comparerThe equality comparison implementation to use when comparing keys.

◆ concurrent_dictionary() [10/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( xtd::usize concurrent_level,
xtd::usize capacity,
const xtd::collections::generic::iequality_comparer< key_type > & comparer )
inline

Initializes a new instance of the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> class that is empty, has the specified concurrency level and capacity, and uses the specified xtd::collections::generic::iequality_comparer<key_type>.

Parameters
concurrent_levelThe estimated number of threads that will update the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> concurrently,.
capacityThe initial number of elements that the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> can contain.
comparerThe equality comparison implementation to use when comparing keys.

◆ concurrent_dictionary() [11/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( std::initializer_list< std::pair< key_t, value_t > > items)
inline

Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a variety of data sources.

Parameters
initInitializer list to initialize the elements of the container with.
Exceptions
xtd::argument_exceptiondictionary contains one or more duplicate keys.
Remarks
Initializer-list constructor. Constructs the container with the contents of the initializer list init, same as
concurrent_dictionary(init.begin(), init.end())

◆ concurrent_dictionary() [12/12]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::concurrent_dictionary ( std::initializer_list< value_type > items)
inline

Constructs the container with the contents of the specified initializer list, and allocator.

Parameters
itemsThe initializer list to initialize the elements of the container with.

Member Function Documentation

◆ comparer()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::comparer ( ) const -> const xtd::collections::generic::iequality_comparer< key_t > &
inlinenodiscardnoexcept

Gets the xtd::collections::generic::iequality_comparer <type_t> that is used to determine equality of keys for the dictionary.

Returns
The xtd::collections::generic::iequality_comparer <type_t> generic interface implementation that is used to determine equality of keys for the current xtd::collections::generic::dictionary <key_t, value_t> and to provide hash values for the keys.
Remarks
xtd::collections::generic::dictionary <key_t, value_t> requires an equality implementation to determine whether keys are equal. You can specify an implementation of the xtd::collections::generic::iequality_comparer <type_t> generic interface by using a constructor that accepts a comparer parameter; if you do not specify one, the default generic equality comparer td::collections::generic::equality_comparer::default_equality_comparer is used.

◆ count()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::count ( ) const -> xtd::usize
inlinenodiscardoverridevirtualnoexcept

Gets the number of elements contained in the xtd::collections::generic::icollection.

Returns
The number of elements contained in the xtd::collections::generic::icollection.

Implements xtd::collections::generic::idictionary< key_t, value_t >.

◆ is_empty()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::is_empty ( ) const -> bool
inlinenodiscardnoexcept

Gets a value that indicates whether the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is empty.

Returns
true if the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is empty; otherwise, false.
Remarks
or determining whether the collection contains any items, use of this property is recommended rather than retrieving the number of items from the xtd::collections::concurrent::concurrent_dictionary::count property and comparing it to 0. However, as this collection is intended to be accessed concurrently, it may be the case that another thread will modify the collection after xtd::collections::concurrent::concurrent_dictionary::is_empty returns, thus invalidating the result.

◆ is_read_only()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::is_read_only ( ) const -> bool
inlinenodiscardoverridevirtualnoexcept

Gets a value indicating whether the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is read-only.

Returns
true if the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is read-only; otherwise, false.
Remarks
A collection that is read-only does not allow the addition or removal of elements after the collection is created. Note that read-only in this context does not indicate whether individual elements of the collection can be modified, since the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> interface only supports addition and removal operations. For example, the xtd::collections::concurrent::concurrent_dictionary::is_read_only property of an array that is cast or converted to an xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> object returns true, even though individual array elements can be modified.

Implements xtd::collections::generic::idictionary< key_t, value_t >.

◆ is_synchronized()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::is_synchronized ( ) const -> bool
inlinenodiscardoverridevirtualnoexcept

Gets a value indicating whether access to the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is synchronized (thread safe).

Returns
true if access to the ICollection is synchronized (thread safe); otherwise, false.
Remarks
xtd::collections::concurrent::iproducer_consumer_collection::sync_root returns an object, which can be used to synchronize access to the xtd::collections::generic::icollection.
Most collection classes in the xtd::collections namespace also implement a Synchronized method, which provides a synchronized wrapper around the underlying collection.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
The following code example shows how to lock the collection using the xtd::collections::concurrent::iproducer_consumer_collection::sync_root property during the entire enumeration.
icollection& my_collection = some_collection;
lock(my_collection.sync_root()) {
for (const auto& item : my_collection) {
// Insert your code here.
}
}
virtual auto sync_root() const noexcept -> const xtd::object &=0
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
generic::icollection< xtd::any_object > icollection
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition icollection.hpp:32

Implements xtd::collections::generic::idictionary< key_t, value_t >.

◆ keys()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::keys ( ) const -> key_collection
inlineoverridevirtualnoexcept

Gets a collection containing the keys in the xtd::collections::generic::ictionary<key_t,value_t>.

Returns
A collection of keys in the xtd::collections::generic::ictionary<key_t,value_t>.
Remarks
The property returns a copy of all the keys. It's not kept in sync with xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.

Implements xtd::collections::generic::idictionary< key_t, value_t >.

◆ values()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::values ( ) const -> value_collection
inlineoverridevirtualnoexcept

Gets a collection that contains the values in the xtd::collections::generic::ictionary<key_t,value_t>.

Returns
A collection that contains the values in the xtd::collections::generic::ictionary<key_t,value_t>.
Remarks
The property returns a copy of all the values. It's not kept in sync with xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.

Implements xtd::collections::generic::idictionary< key_t, value_t >.

◆ add_or_update() [1/3]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::add_or_update ( const key_t & key,
xtd::callable< value_t, key_t > auto && add_value_factory,
xtd::callable< value_t, key_t, value_t > auto && update_value_factory ) -> const value_t &
inline

Uses the specified functions to add a key/value pair to the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key does not already exist, or to update a key/value pair in the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key already exists.

Parameters
keyThe key to be added or whose value should be updated.
add_value_factory
update_value_factory
Returns
The new value for the key. This will be either be the result of add_value_factory (if the key was absent) or the result of update_value_factory (if the key was present).
Remarks
If you call xtd::collections::concurrent::concurrent_dictionary::add_or_update simultaneously on different threads, addValueFactory may be called multiple times, but its key/value pair might not be added to the dictionary for every call.

◆ add_or_update() [2/3]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::add_or_update ( const key_t & key,
const value_t & add_value,
xtd::callable< value_t, key_t, value_t > auto && update_value_factory ) -> const value_t &
inline

Adds a key/value pair to the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key does not already exist, or updates a key/value pair in the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> by using the specified function if the key already exists.

Parameters
keyThe key to be added or whose value should be updated.
valueThe value to be added for an absent key.
update_value_factoryThe function used to generate a new value for an existing key based on the key's existing value.
Returns
The new value for the key. This will be either be add_value (if the key was absent) or the result of update_value_factory (if the key was present).

◆ add_or_update() [3/3]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
template<typename arg_t>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::add_or_update ( const key_t & key,
xtd::callable< value_t, key_t, arg_t > auto && add_value_factory,
xtd::callable< value_t, key_t, value_t, arg_t > auto && update_value_factory,
arg_t && factory_argument ) -> const value_t &
inline

Uses the specified functions and argument to add a key/value pair to the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key does not already exist, or to update a key/value pair in the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> if the key already exists.

Parameters
keyThe key to be added or whose value should be updated.
add_value_factoryThe function used to generate a value for an absent key.
update_value_factoryThe function used to generate a new value for an existing key based on the key's existing value.
factory_argumentAn argument to pass into add_value_factory and update_value_factory.
Returns
The new value for the key. This will be either be the result of add_value_factory (if the key was absent) or the result of update_value_factory (if the key was present).
Remarks
If you call xtd::collections::concurrent::concurrent_dictionary::add_or_update simultaneously on different threads, addValueFactory may be called multiple times, but its key/value pair might not be added to the dictionary for every call.

◆ clear()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::clear ( ) -> void
inlineoverridevirtual

◆ contains_key()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::contains_key ( const key_t & key) const -> bool
inlineoverridevirtualnoexcept

Determines whether the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> contains the specified key.

Parameters
keyThe key to locate in the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.
Returns
true if the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> contains an element with the specified key; otherwise, false.

Implements xtd::collections::generic::idictionary< key_t, value_t >.

◆ copy_to()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::copy_to ( xtd::array< value_type > & array,
xtd::usize array_index ) const -> void
inlineoverride

Copies the elements of the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> to an xtd::array, starting at a particular xtd::array index.

Parameters
arrayThe one-dimensional xtd::array that is the destination of the elements copied from xtd::collections::concurrent::concurrent_dictionary <key_t, value_t>. The xtd::array must have zero-based indexing.
array_indexThe zero-based index in array at which copying begins.
Exceptions
xtd::argument_exceptionThe number of elements in the source xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is greater than the available space from array_index to the end of the destination array.

◆ get_enumerator()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::get_enumerator ( ) const -> xtd::collections::generic::enumerator< value_type >
inlinenodiscardoverridevirtual

Returns an enumerator that iterates through a collection.

Returns
An xtd::collections::generic::enumerator object that can be used to iterate through the collection.
Todo
: use enumerator with a snapshot of the collection instead reference : enumerator {items_, enumerator_mode::snapshot};

Implements xtd::collections::generic::idictionary< key_t, value_t >.

◆ get_or_add() [1/3]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::get_or_add ( const key_t & key,
xtd::callable< value_t, key_t > auto && add_value_factory ) -> const value_t &
inlinenodiscard

Adds a key/value pair to the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> by using the specified function if the key does not already exist. Returns the new value, or the existing value if the key exists.

Parameters
keyThe key of the element to add.
ad_value_factoryThe function used to generate a value for the key.
Returns
The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.

◆ get_or_add() [2/3]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::get_or_add ( const key_t & key,
const value_t & add_value ) -> const value_t &
inlinenodiscard

Adds a key/value pair to the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> if the key does not already exist. Returns the new value, or the existing value if the key exists.

Parameters
keyThe key of the element to add.
add_valueThe value to be added, if the key does not already exist.
Returns
The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.

◆ get_or_add() [3/3]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
template<typename arg_t>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::get_or_add ( const key_t & key,
xtd::callable< value_t, key_t, arg_t > auto && add_value_factory,
arg_t && factory_argument ) -> const value_t &
inlinenodiscard

Adds a key/value pair to the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> by using the specified function and an argument if the key does not already exist, or returns the existing value if the key exists.

Parameters
keyThe key of the element to add.
ad_value_factoryThe function used to generate a value for the key.
factory_argumentAn argument value to pass into valueFactory.
Returns
The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.

◆ to_array()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::to_array ( ) const -> xtd::array< value_type >
inlinenodiscard

Copies the elements contained in the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> to a new array.

Returns
A new array containing the elements copied from the xtd::collections::concurrent::iproducer_consumer_collection <type_t.
Remarks
The method provides a snapshot of the underlying collection. It is possible for other threads to add or remove items immediately after the array is made.

◆ to_string()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::to_string ( ) const -> xtd::string
inlinenodiscardoverridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.

◆ try_add()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::try_add ( const key_t & key,
const value_t & value ) -> bool
inline

Attempts to add the specified key and value to the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t>.

Parameters
keyThe key of the element to add.
valueThe value of the element to add. The value can be null for reference types.
Returns
true if the key/value pair was added to the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> successfully; false if the key already exists.

◆ try_get_value()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::try_get_value ( const key_t & key,
value_t & value ) const -> bool
inlineoverridevirtual

Attempts to get the value associated with the specified key from the xtd::collections::concurrent::concurrent_dictionary <key_t,value_t>.

Parameters
keyThe key of the value to get.
Returns
value When this method returns, contains the object from the xtd::collections::concurrent::concurrent_dictionary<key_t,value_t> that has the specified key, or the default value of the type if the operation failed.

Implements xtd::collections::generic::idictionary< key_t, value_t >.

◆ try_remove() [1/3]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::try_remove ( const key_t & key) -> bool
inline

Attempts to remove and return the value that has the specified key from the xtd::collections::concurrent::concurrent_dictionary <key_t,value_t>.

Parameters
keyThe key of the element to remove and return.
Returns
true if the object was removed successfully; otherwise, false.

◆ try_remove() [2/3]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::try_remove ( const key_t & key,
value_t & value ) -> bool
inline

Attempts to remove and return the value that has the specified key from the xtd::collections::concurrent::concurrent_dictionary <key_t,value_t>.

Parameters
keyThe key of the element to remove and return.
valueWhen this method returns, contains the object removed from the xtd::collections::concurrent::concurrent_dictionary <key_t,value_t>, or the default value of the value_t type if key does not exist.
Returns
true if the object was removed successfully; otherwise, false.

◆ try_remove() [3/3]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::try_remove ( const xtd::collections::generic::key_value_pair< key_t, value_t > & item) -> bool
inline

Removes a key and value from the dictionary. @pram item The xtd::collections::generic::key_value_pair<key_t,value_t> representing the key and value to remove.

Returns
true if the key and value represented by item are successfully found and removed; otherwise, false.
Remarks
Both the specifed key and value must match the entry in the dictionary for it to be removed.
The key is compared using the dictionary's comparer (or the default comparer for key_t if no comparer was provided to the dictionary when it was constructed). The value is compared using the default comparer for value_t.

◆ try_update()

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::try_update ( const key_t & key,
const value_t & new_value,
const value_t & comparison_value ) -> bool
inline

Updates the value associated with key to new_value if the existing value with key is equal to comparison_value.

Parameters
keyThe key of the value that is compared with comparison_value and possibly replaced.
new_valueThe value that replaces the value of the element that has the specified key if the comparison results in equality.
comparison_valueThe value that is compared with the value of the element that has the specified key.
Returns
true if the value with key was equal to comparison_value and was replaced with new_value; otherwise, false.

◆ operator[]() [1/2]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::operator[] ( const key_t & key) const -> const value_t &
inlineoverride

Gets the element with the specified key.

Parameters
keyThe key of the element to get.
Returns
The element with the specified key.
Exceptions
xtd::collections::generic::key_not_found_exceptionThe property is retrieved and key is not found.
xtd::not_supported_exceptionThe property is set and the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is read-only.
Remarks
This property provides the ability to access a specific element in the collection by using the following syntax: my_collection[key].
You can also use the operator [] to add new elements by setting the value of a key that does not exist in the dictionary; for example, my_collection["my_nonexistent_key"] = my_value. However, if the specified key already exists in the dictionary, setting the operator [] overwrites the old value. In contrast, the xtd::collections::generic::dictionary::add method does not modify existing elements.

◆ operator[]() [2/2]

template<typename key_t, typename value_t, typename hasher_t = xtd::collections::generic::helpers::hasher<key_t>, typename equator_t = xtd::collections::generic::helpers::equator<key_t>, typename allocator_t = xtd::collections::generic::helpers::allocator<std::pair<const key_t, value_t>>>
auto xtd::collections::concurrent::concurrent_dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >::operator[] ( const key_t & key) -> value_t &
inlineoverridevirtual

Sets the element with the specified key.

Parameters
keyThe key of the element to set.
Returns
The element with the specified key.
Exceptions
xtd::not_supported_exceptionThe property is set and the xtd::collections::concurrent::concurrent_dictionary <key_t, value_t> is read-only.
Remarks
This property provides the ability to access a specific element in the collection by using the following syntax: my_collection[key].
You can also use the operator [] to add new elements by setting the value of a key that does not exist in the dictionary; for example, my_collection["my_nonexistent_key"] = my_value. However, if the specified key already exists in the dictionary, setting the operator [] overwrites the old value. In contrast, the xtd::collections::generic::dictionary::add method does not modify existing elements.

Implements xtd::collections::generic::idictionary< key_t, value_t >.


The documentation for this class was generated from the following file: