xtd 0.2.0
Loading...
Searching...
No Matches
xtd::collections::generic::idictionary< key_t, value_t > Class Template Referenceabstract
Inheritance diagram for xtd::collections::generic::idictionary< key_t, value_t >:
xtd::collections::generic::ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > > xtd::interface xtd::collections::generic::extensions::enumerable_iterators< type_t, enumerable_t > xtd::collections::generic::extensions::enumerable< enumerable_t, source_t > xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >

Definition

template<typename key_t, typename value_t>
class xtd::collections::generic::idictionary< key_t, value_t >

Represents a generic collection of key/value pairs.

Definition
template<typename type_t>
Represents a generic collection of key/value pairs.
Definition idictionary.hpp:35
#define interface_
This keyword is use to represent an interface.
Definition interface.hpp:58
Header
#include <xtd/collections/generic/idictionary
Namespace
xtd::collections::generic
Library
xtd.core
Remarks
The idictionary <key_t, value_t> interface is the base interface for generic collections of key/value pairs.
Each element is a key/value pair stored in a key_value_pair <key_t, value_t> object.
Each pair must have a unique key. Implementations can vary in whether they allow key to be empty. The value can be empty and does not have to be unique. The idictionary <key_t, value_t> interface allows the contained keys and values to be enumerated, but it does not imply any particular sort order.
The foreach statement of the C# language (For Each in Visual Basic, for each in C++) returns an object of the type of the elements in the collection. Since each element of the IDictionary<TKey,TValue> is a key/value pair, the element type is not the type of the key or the type of the value. Instead, the element type is KeyValuePair<TKey,TValue>. For example:

Public Aliases

using key_type = key_t
 Represents the dictionary key type.
 
using mapped_type = value_t
 Represents the dictionary mapped type.
 
using value_type = xtd::collections::generic::key_value_pair< key_type, mapped_type >
 Represents the dictionary value type.
 
using iterator = typename xtd::collections::generic::icollection< value_type >::iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
 
using const_iterator = typename xtd::collections::generic::icollection< value_type >::const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
 
using key_collection = xtd::collections::generic::list< key_type >
 Represents the idictionary key collection type.
 
using value_collection = xtd::collections::generic::list< mapped_type >
 Represents the idictionary value collection type.
 

Public Properties

virtual key_collection keys () const noexcept=0
 Gets an xtd::collections::generic::icollection <type_t> containing the keys of the xtd::collections::generic::idictionary <key_t, value_t>.
 
virtual value_collection values () const noexcept=0
 Gets an xtd::collections::generic::icollection <type_t> containing the values of the xtd::collections::generic::idictionary <key_t, value_t>.
 

Public Methods

virtual void add (const key_t &key, const value_t value)=0
 Adds an element with the provided key and value to the xtd::collections::generic::idictionary <key_t, value_t>.
 

Public Operators

virtual const value_t & operator[] (const key_t &key) const =0
 Gets the element with the specified key.
 
virtual value_t & operator[] (const key_t &key)=0
 Sets the element with the specified key.
 

Additional Inherited Members

- Public Types inherited from xtd::collections::generic::ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > >
using iterator = typename 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 > > >::iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
 
using const_iterator = typename 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 > > >::const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
 
- Public Types inherited from xtd::collections::generic::extensions::enumerable_iterators< type_t, enumerable_t >
using const_iterator = const iterator
 Represents the const iterator of enumarable value type.
 
- Public Types inherited from xtd::collections::generic::extensions::enumerable< enumerable_t, source_t >
template<typename type_t >
using ienumerable = typename xtd::linq::enumerable::ienumerable< type_t >
 Represents the ienumerable value type.
 
template<typename type_t >
using list = typename xtd::linq::enumerable::list< type_t >
 Represents the list value type.
 
- Public Member Functions inherited from xtd::collections::generic::ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > >
virtual xtd::collections::generic::enumerator< xtd::collections::generic::key_value_pair< key_t, value_t > > get_enumerator () const=0
 Returns an enumerator that iterates through a collection.
 
- Public Member Functions inherited from xtd::collections::generic::extensions::enumerable_iterators< type_t, enumerable_t >
virtual const_iterator begin () const
 Returns an iterator to the first element of the enumarable.
 
virtual iterator begin ()
 Returns an iterator to the first element of the enumarable.
 
virtual const_iterator cbegin () const
 Returns an iterator to the first element of the enumarable.
 
virtual const_iterator cend () const
 Returns an iterator to the element following the last element of the enumarable.
 
virtual const_iterator end () const
 Returns an iterator to the element following the last element of the enumarable.
 
virtual iterator end ()
 Returns an iterator to the element following the last element of the enumarable.
 
- Public Member Functions inherited from xtd::collections::generic::extensions::enumerable< enumerable_t, source_t >
source_t aggregate (const std::function< source_t(const source_t &, const source_t &)> &func) const
 Applies an accumulator function over a sequence.
 
source_t aggregate (const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func) const
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
template<typename accumulate_t >
accumulate_t aggregate (const accumulate_t &seed, const std::function< accumulate_t(const source_t &, const accumulate_t &)> &func) const
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
source_t aggregate (const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func, const std::function< source_t(const source_t &)> &result_selector) const
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
template<typename result_t , typename accumulate_t >
result_t aggregate (const accumulate_t &seed, const std::function< accumulate_t(const source_t &, const accumulate_t &)> &func, const std::function< result_t(const accumulate_t &)> &result_selector) const
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
bool all (const std::function< bool(const source_t &)> &predicate) const
 Determines whether all elements of a sequence satisfy a condition.
 
bool any () const noexcept
 Determines whether a sequence contains any elements.
 
bool any (const std::function< bool(const source_t &)> &predicate) const
 Determines whether any element of a sequence satisfies a condition.
 
const ienumerable< source_t > & append (const source_t &element) const noexcept
 Appends a value to the end of the sequence.
 
const ienumerable< source_t > & as_enumerable () const noexcept
 Returns the input typed as xtd::collection::generic::ienumerable <type_t>.
 
auto average () const noexcept
 Computes the average of a sequence of source_t values.
 
template<typename result_t >
const ienumerable< result_t > & cast () const noexcept
 Casts the elements of an xtd::collection::generic::ienumerable to the specified type.
 
const ienumerable< xtd::array< source_t > > & chunk (size_t size) const
 Splits the elements of a sequence into chunks of size at most size.
 
const ienumerable< source_t > & concat (const ienumerable< source_t > &second) const noexcept
 Concatenates two sequences.
 
bool contains (const source_t &value) const noexcept
 Determines whether a sequence contains a specified element by using the default equality comparer.
 
bool contains (const source_t &value, const xtd::collections::generic::iequality_comparer< source_t > &comparer) const noexcept
 Determines whether a sequence contains a specified element by using a specified equality comparer.
 
size_t count () const noexcept
 Returns the number of elements in current sequence.
 
size_t count (const std::function< bool(const source_t &)> &predicate) const noexcept
 Returns a number that represents how many elements in the specified sequence satisfy a condition.
 
template<typename key_t >
const ienumerable< key_value_pair< key_t, xtd::size > > & count_by (const std::function< key_t(const source_t &)> &key_selector) const noexcept
 Returns the count of elements in the current sequence grouped by key.
 
template<typename key_t >
const ienumerable< key_value_pair< key_t, xtd::size > > & count_by (const std::function< key_t(const source_t &)> &key_selector, const iequality_comparer< key_t > &key_comparer) const noexcept
 Returns the count of elements in the current sequence grouped by key.
 
const ienumerable< source_t > & default_if_empty () const noexcept
 Returns the elements of the specified sequence or the type parameter's default value in a singleton collection if the current sequence is empty.
 
const ienumerable< source_t > & default_if_empty (const source_t &default_value) const noexcept
 Returns the elements of the specified sequence or the specified value in a singleton collection if the current sequence is empty.
 
source_t first_or_default (const std::function< bool(const source_t &)> &predicate, const source_t &default_value) const noexcept
 Returns the first element of the sequence that satisfies a condition, or a specified default value if no such element is found.
 
source_t first_or_default (const std::function< bool(const source_t &)> &predicate) const noexcept
 Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
 
source_t first_or_default (const source_t default_value) const noexcept
 Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
 
source_t first_or_default () const noexcept
 Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
 
template<typename result_t >
const ienumerable< result_t > & select (const std::function< result_t(const source_t &)> &selector) const
 Projects each element of a sequence into a new form.
 
const ienumerable< source_t > & select (const std::function< source_t(const source_t &)> &selector) const
 Projects each element of a sequence into a new form.
 
template<typename result_t >
const ienumerable< result_t > & select (const std::function< result_t(const source_t &, size_t index)> &selector) const
 Projects each element of a sequence into a new form by incorporating the element's index.
 
const ienumerable< source_t > & select (const std::function< source_t(const source_t &, size_t index)> &selector) const
 Projects each element of a sequence into a new form by incorporating the element's index.
 
const list< source_t > & to_list () const noexcept
 Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <type_t>.
 
const ienumerable< source_t > & where (const std::function< bool(const source_t &)> &predicate) const
 Filters a sequence of values based on a predicate.
 
const ienumerable< source_t > & where (const std::function< bool(const source_t &, size_t)> &predicate) const
 Filters a sequence of values based on a predicate. Each element's index is used in the logic of the predicate function.
 

Member Typedef Documentation

◆ key_type

template<typename key_t , typename value_t >
using xtd::collections::generic::idictionary< key_t, value_t >::key_type = key_t

Represents the dictionary key type.

◆ mapped_type

template<typename key_t , typename value_t >
using xtd::collections::generic::idictionary< key_t, value_t >::mapped_type = value_t

Represents the dictionary mapped type.

◆ value_type

template<typename key_t , typename value_t >
using xtd::collections::generic::idictionary< key_t, value_t >::value_type = xtd::collections::generic::key_value_pair<key_type, mapped_type>

Represents the dictionary value type.

◆ iterator

template<typename key_t , typename value_t >
using xtd::collections::generic::idictionary< key_t, value_t >::iterator = typename xtd::collections::generic::icollection<value_type>::iterator

Represents the iterator of xtd::collections::generic::ienumerable value type.

◆ const_iterator

template<typename key_t , typename value_t >
using xtd::collections::generic::idictionary< key_t, value_t >::const_iterator = typename xtd::collections::generic::icollection<value_type>::const_iterator

Represents the const iterator of xtd::collections::generic::ienumerable value type.

◆ key_collection

template<typename key_t , typename value_t >
using xtd::collections::generic::idictionary< key_t, value_t >::key_collection = xtd::collections::generic::list<key_type>

Represents the idictionary key collection type.

◆ value_collection

template<typename key_t , typename value_t >
using xtd::collections::generic::idictionary< key_t, value_t >::value_collection = xtd::collections::generic::list<mapped_type>

Represents the idictionary value collection type.

Member Function Documentation

◆ keys()

template<typename key_t , typename value_t >
virtual key_collection xtd::collections::generic::idictionary< key_t, value_t >::keys ( ) const
pure virtualnoexcept

Gets an xtd::collections::generic::icollection <type_t> containing the keys of the xtd::collections::generic::idictionary <key_t, value_t>.

Returns
An xtd::collections::generic::icollection <type_t> containing the keys of the object that implements xtd::collections::generic::idictionary <key_t, value_t>.
Remarks
The order of the keys in the returned xtd::collections::generic::icollection <type_t> is unspecified, but it is guaranteed to be the same order as the corresponding values in the xtd::collections::generic::icollection <type_t> returned by the xtd::collections::generic::idictionary::values property.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >.

◆ values()

template<typename key_t , typename value_t >
virtual value_collection xtd::collections::generic::idictionary< key_t, value_t >::values ( ) const
pure virtualnoexcept

Gets an xtd::collections::generic::icollection <type_t> containing the values of the xtd::collections::generic::idictionary <key_t, value_t>.

Returns
An xtd::collections::generic::icollection <type_t> containing the values of the object that implements xtd::collections::generic::idictionary <key_t, value_t>.
Remarks
The order of the values in the returned xtd::collections::generic::icollection <type_t> is unspecified, but it is guaranteed to be the same order as the corresponding values in the xtd::collections::generic::icollection <type_t> returned by the xtd::collections::generic::idictionary::keys property.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >.

◆ add()

template<typename key_t , typename value_t >
virtual void xtd::collections::generic::idictionary< key_t, value_t >::add ( const key_t &  key,
const value_t  value 
)
pure virtual

Adds an element with the provided key and value to the xtd::collections::generic::idictionary <key_t, value_t>.

Parameters
keyThe object to use as the key of the element to add.
valueThe object to use as the value of the element to add.
Exceptions
xtd::argument_exceptionAn element with the same key already exists in the xtd::collections::generic::idictionary <key_t, value_t>.
xtd::not_supported_exceptionThe xtd::collections::generic::idictionary <key_t, value_t> is read-only.
Remarks
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::idictionary::add method does not modify existing elements.
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer::default_comparer, whereas the xtd::collections::generic::dictionary <key_t,value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t> implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >.

◆ operator[]() [1/2]

template<typename key_t , typename value_t >
virtual const value_t & xtd::collections::generic::idictionary< key_t, value_t >::operator[] ( const key_t &  key) const
pure virtual

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::generic::idictionary <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::idictionary::add method does not modify existing elements.
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer::default_comparer, whereas the xtd::collections::generic::dictionary <key_t,value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t> implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >.

◆ operator[]() [2/2]

template<typename key_t , typename value_t >
virtual value_t & xtd::collections::generic::idictionary< key_t, value_t >::operator[] ( const key_t &  key)
pure virtual

Sets the element with the specified key.

Parameters
keyThe key of the element to set.
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::generic::idictionary <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::idictionary::add method does not modify existing elements.
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer::default_comparer, whereas the xtd::collections::generic::dictionary <key_t,value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t> implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >.


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