11#include "../../argument_out_of_range_exception.hpp"
12#include "../../new_ptr.hpp"
13#include "../../ptr.hpp"
15#include <unordered_map>
20 namespace collections {
66 template<
class key_t,
class value_t,
class hasher_t = helpers::hasher<key_t>,
class equator_t = helpers::equator<key_t>,
class allocator_t = helpers::allocator<std::pair<const key_t, value_t>>>
92 return hasher_t {}(key);
125 if (&
a == &
b)
return true;
127 return equator_t {}(
a,
b);
159 using base_type = std::unordered_map<key_type, mapped_type, hasher, key_equal, allocator_type>;
165 using pointer =
typename std::allocator_traits<allocator_t>::pointer;
167 using const_pointer =
typename std::allocator_traits<allocator_t>::const_pointer;
241 for (
const auto& item : collection)
250 template<
class equality_comparer_t>
301 template<
class equality_comparer_t>
312 template<
class equality_comparer_t>
314 for (
const auto& item : collection)
328 template<
class equality_comparer_t>
350 template <
class input_iterator_t>
353 const auto& [key, value] = *
iterator;
365 template <
class input_iterator_t>
368 const auto& [key, value] = *
iterator;
381 template <
class input_iterator_t>
384 const auto& [key, value] = *
iterator;
416 const auto& [key, value] = *
iterator;
430 const auto& [key, value] = *
iterator;
446 dictionary(std::unordered_map<key_t, value_t>&&
other) noexcept : data_(xtd::new_ptr<data>(std::move(
other.data_->items))) {}
463 for (
const auto& [key, value] : init)
477 for (
const auto& [key, value] : init)
492 for (
const auto& [key, value] : init)
507 template <
class init_key_t,
class init_value_t>
509 for (
const auto& [key, value] : init)
522 template <
class init_key_t,
class init_value_t>
524 for (
const auto& [key, value] : init)
538 template <
class init_key_t,
class init_value_t>
540 for (
const auto& [key, value] : init)
577 if (data_->comparer)
return *data_->comparer;
590 bool empty() const noexcept {
return data_->items.empty();}
634 for (
const auto& [key, value] : data_->items)
695 for (
const auto& [key, value] : data_->items)
710 void add(
const key_t& key,
const value_t value)
override {
718 add(item.key(), item.value());
727 const value_t&
at(
const key_t& key)
const {
728 auto iterator = data_->items.find(key);
738 value_t&
at(
const key_t& key) {
739 auto iterator = data_->items.find(key);
749 return data_->items.begin(
n);
757 return data_->items.begin(
n);
775 return data_->items.begin(
n);
783 return data_->items.end(
n);
789 data_->items.clear();
796 return data_->items.find(key) != data_->items.end();
801 template <
class contains_key_t>
803 return data_->items.find(
x) != data_->items.end();
812 return iterator->value() == item.value();
823 bool contains_value(
const value_t& value)
const noexcept {
824 for (
const auto& [item_key, item_value] : *this)
825 if (item_value == value) return true;
836 for (
const auto& item : *
this)
837 array[array_index + index++] = item;
848 template <
class ...args_t>
850 const auto& [
iterator, succeeded] = data_->items.emplace(std::forward<args_t>(args)...);
851 if (succeeded) ++data_->version;
852 return {to_type_iterator(
iterator), succeeded};
863 template <
class ...args_t>
866 return to_type_iterator(data_->items.emplace_hint(to_base_type_iterator(hint), std::forward<args_t>(args)...));
874 return data_->items.end(
n);
882 return data_->items.end(
n);
898 const auto& [first, last] = data_->items.equal_range(key);
899 return {to_type_iterator(first), to_type_iterator(last)};
906 template <
class equal_range_key_t>
908 const auto& [first, last] = data_->items.equal_range(key);
909 return {to_type_iterator(first), to_type_iterator(last)};
916 template <
class equal_range_key_t>
918 const auto& [first, last] = data_->items.equal_range(
x);
919 return {to_type_iterator(first), to_type_iterator(last)};
927 const auto& [first, last] = data_->items.equal_range(
x);
928 return {to_type_iterator(first), to_type_iterator(last)};
940 return to_type_iterator(data_->items.erase(to_base_type_iterator(pos)));
952 return to_type_iterator(data_->items.erase(to_base_type_iterator(first), to_base_type_iterator(last)));
962 auto removed_count = data_->items.erase(key);
963 if (removed_count) ++data_->version;
964 return removed_count;
975 return data_->items.extract(to_base_type_iterator(position));
985 return data_->items.extract(
k);
993 return to_type_iterator(data_->items.find(key));
1001 return to_type_iterator(data_->items.find(key));
1008 template <
class find_key_t>
1010 return to_type_iterator(data_->items.find(
x));
1016 template <
class find_key_t>
1018 return to_type_iterator(data_->items.find(
x));
1028 struct internal_enumerator :
public ienumerator<value_type> {
1034 if (iterator_ != items_.items().cend()) {
1035 static thread_local auto value =
value_type {};
1039 static auto default_value_type =
value_type {};
1040 return default_value_type;
1043 bool move_next()
override {
1045 if (!reset_)
return ++iterator_ != items_.items().cend();
1047 iterator_ = items_.items().cbegin();
1048 return iterator_ != items_.items().cend();
1051 void reset()
override {
1053 version_ = items_.data_->version;
1054 iterator_ = items_.items().cend();
1060 typename dictionary::base_type::const_iterator iterator_ = items_.
items().cend();
1063 return {new_ptr<internal_enumerator>(*
this, data_->version)};
1070 return data_->items.hash_function();
1080 const auto& [
iterator, succeeded] = data_->items.insert(value);
1081 if (succeeded) ++data_->version;
1082 return {to_type_iterator(
iterator), succeeded};
1091 const auto& [
iterator, succeeded] = data_->items.insert(value);
1092 if (succeeded) ++data_->version;
1093 return {to_type_iterator(
iterator), succeeded};
1102 template <
class type_t>
1104 const auto& [
iterator, succeeded] = data_->items.insert(value);
1105 if (succeeded) ++data_->version;
1106 return {to_type_iterator(
iterator), succeeded};
1117 return to_type_iterator(data_->items.insert(to_base_type_iterator(hint), value));
1128 return to_type_iterator(data_->items.insert(to_base_type_iterator(hint), value));
1138 template <
class type_t>
1141 return to_type_iterator(data_->items.insert(to_base_type_iterator(hint), value));
1150 template <
class input_iterator_t>
1151 void insert(input_iterator_t first, input_iterator_t last) {
1153 const auto& [key, value] = *
iterator;
1163 for (
const auto& [key, value] :
ilist)
1164 add(std::forward<value_type>({key, value}));
1171 template <
class init_key_t,
class init_value_t>
1173 for (
const auto& [key, value] :
ilist)
1174 add(std::forward<value_type>({key, value}));
1187 return data_->items.inser(nh);
1199 return to_type_iterator(data_->items.inser(to_base_type_iterator(hint), nh));
1209 template <
class type_t>
1211 const auto& [
iterator, succeeded] = data_->items.insert_or_assign(
k, obj);
1212 if (succeeded) ++data_->version;
1213 return {to_type_iterator(
iterator), succeeded};
1222 template <
class type_t>
1224 const auto& [
iterator, succeeded] = data_->items.insert_or_assign(std::move(
k), obj);
1225 if (succeeded) ++data_->version;
1226 return {to_type_iterator(
iterator), succeeded};
1236 template <
class type_t>
1239 return to_type_iterator(data_->items.insert_or_assign(to_base_type_iterator(hint),
k, obj));
1249 template <
class type_t>
1252 return to_type_iterator(data_->items.insert_or_assign(to_base_type_iterator(hint), std::move(
k), obj));
1259 return data_->items.key_eq();
1266 template <
class source_hasher_t,
class source_equator_t>
1268 data_->items.merge(source.
items);
1276 template <
class source_hasher_t,
class source_equator_t>
1278 data_->items.merge(std::move(source.items));
1286 template <
class source_hasher_t,
class source_equator_t>
1287 void merge(std::unordered_map<key_t, value_t, source_hasher_t,source_equator_t, allocator_t>& source) {
1288 data_->items.merge(source);
1296 template <
class source_hasher_t,
class source_equator_t>
1297 void merge(std::unordered_map<key_t, value_t, source_hasher_t,source_equator_t, allocator_t>&& source) {
1298 data_->items.merge(std::move(source));
1306 template <
class source_hasher_t,
class source_equator_t>
1307 void merge(std::unordered_multimap<key_t, value_t, source_hasher_t,source_equator_t, allocator_t>& source) {
1308 data_->items.merge(source);
1316 template <
class source_hasher_t,
class source_equator_t>
1317 void merge(std::unordered_multimap<key_t, value_t, source_hasher_t,source_equator_t, allocator_t>&& source) {
1318 data_->items.merge(std::move(source));
1327 data_->items.rehash(
count);
1334 bool remove(
const key_t& key)
noexcept override {
1335 return erase(key) == 1;
1342 if (!contains_value(item.value()))
return false;
1343 return erase(item.key()) == 1;
1349 bool remove(
const key_t& key, value_t& value)
noexcept {
1360 data_->items.reserve(
count);
1368 data_->items.swap(
other.data_->items);
1369 std::swap(data_->version,
other.data_->version);
1400 bool try_add(
const key_t& key,
const value_t value)
noexcept {
1401 const auto& [
iterator, succeeded] = data_->items.insert(std::forward<base_value_type>({key, value}));
1402 if (succeeded) ++data_->version;
1413 template <
class ...args_t>
1415 const auto& [
iterator, succeeded] = to_type_iterator(data_->items.try_emplace(
k, std::forward<args_t>(args)...));
1416 if (succeeded) ++data_->version;
1417 return {to_type_iterator(
iterator), succeeded};
1426 template <
class ...args_t>
1428 const auto& [
iterator, succeeded] = to_type_iterator(data_->items.try_emplace(std::move(
k), std::forward<args_t>(args)...));
1429 if (succeeded) ++data_->version;
1430 return {to_type_iterator(
iterator), succeeded};
1440 template <
class ...args_t>
1443 return to_type_iterator(data_->items.try_emplace(to_base_type_iterator(hint),
k, std::forward<args_t>(args)...));
1453 template <
class ...args_t>
1456 return to_type_iterator(data_->items.try_emplace(to_base_type_iterator(hint), std::move(
k), std::forward<args_t>(args)...));
1481 data_->comparer = std::move(
other.data_->comparer);
1482 data_->items = std::move(
other.data_->items);
1483 data_->version = std::move(
other.data_->version);
1490 data_->items = std::move(
other);
1502 data_->items.clear();
1503 for (
const auto& [key, value] :
other)
1510 data_->items.clear();
1511 for (
const auto& [key, value] :
ilist)
1517 template <
class init_key_t,
class init_value_t>
1519 data_->items.clear();
1520 for (
const auto& [key, value] :
ilist)
1540 return data_->items[key];}
1544 operator const base_type&()
const noexcept {
return data_->items;}
1551 typename base_type::const_iterator to_base_type_iterator(
const_iterator value)
const noexcept {
1555 typename base_type::iterator to_base_type_iterator(
iterator value)
noexcept {
1559 const_iterator to_type_iterator(
typename base_type::const_iterator value)
const noexcept {
1563 iterator to_type_iterator(
typename base_type::iterator value)
noexcept {
1572 for (
const auto& item : items)
1573 this->items.
insert(item);
1576 for (
auto&& item : items)
1577 this->items.
insert(item);
1580 ptr<iequality_comparer<key_t>>
comparer;
1591 template<
class key_t,
class value_t>
1592 dictionary(idictionary<key_t, value_t>) -> dictionary<key_t, value_t, helpers::hasher<key_t>, helpers::equator<key_t>, helpers::allocator<std::pair<const key_t, value_t>>>;
1594 template<
class key_t,
class value_t>
1595 dictionary(ienumerable<key_value_pair<key_t, value_t>>) -> dictionary<key_t, value_t, helpers::hasher<key_t>, helpers::equator<key_t>, helpers::allocator<std::pair<const key_t, value_t>>>;
1597 template<
class key_t,
class value_t,
class hasher_t = helpers::hasher<key_t>,
class equator_t = helpers::equator<key_t>,
class allocator_t = helpers::allocator<std::pair<const key_t, value_t>>>
1598 dictionary(std::initializer_list<key_value_pair<key_t, value_t>>,
xtd::size = 0, hasher_t = hasher_t {}, equator_t = equator_t {}, allocator_t = allocator_t {}) -> dictionary<key_t, value_t, hasher_t, equator_t, allocator_t>;
1600 template<
class key_t,
class value_t,
class allocator_t>
1601 dictionary(std::initializer_list<key_value_pair<key_t, value_t>>,
xtd::size, allocator_t) -> dictionary<key_t, value_t, helpers::hasher<key_t>, helpers::equator<key_t>, allocator_t>;
1603 template<
class key_t,
class value_t,
class allocator_t>
1604 dictionary(std::initializer_list<key_value_pair<key_t, value_t>>, allocator_t) -> dictionary<key_t, value_t, helpers::hasher<key_t>, helpers::equator<key_t>, allocator_t>;
1606 template<
class key_t,
class value_t,
class hasher_t,
class allocator_t>
1607 dictionary(std::initializer_list<key_value_pair<key_t, value_t>>,
xtd::size, hasher_t, allocator_t) -> dictionary<key_t, value_t, hasher_t, helpers::equator<key_t>, allocator_t>;
1609 template<
class key_t,
class value_t,
class hasher_t = helpers::hasher<key_t>,
class equator_t = helpers::equator<key_t>,
class allocator_t = helpers::allocator<std::pair<const key_t, value_t>>>
1610 dictionary(std::initializer_list<std::pair<key_t, value_t>>,
xtd::size bucket_count = 0, hasher_t = hasher_t {}, equator_t = equator_t {}, allocator_t = allocator_t {}) -> dictionary<key_t, value_t, hasher_t, equator_t, allocator_t>;
1612 template<
class key_t,
class value_t,
class allocator_t>
1613 dictionary(std::initializer_list<std::pair<key_t, value_t>>,
xtd::size, allocator_t) -> dictionary<key_t, value_t, helpers::hasher<key_t>, helpers::equator<key_t>, allocator_t>;
1615 template<
class key_t,
class value_t,
class allocator_t>
1616 dictionary(std::initializer_list<std::pair<key_t, value_t>>, allocator_t) -> dictionary<key_t, value_t, helpers::hasher<key_t>, helpers::equator<key_t>, allocator_t>;
1618 template<
class key_t,
class value_t,
class hasher_t,
class allocator_t>
1619 dictionary(std::initializer_list<std::pair<key_t, value_t>>,
xtd::size, hasher_t, allocator_t) -> dictionary<key_t, value_t, hasher_t, helpers::equator<key_t>, allocator_t>;
1621 template<
class input_iterator_t,
class hasher_t = helpers::hasher<helpers::iterator_key_t<input_iterator_t>>,
class equator_t = helpers::equator<helpers::iterator_key_t<input_iterator_t>>,
class allocator_t = helpers::allocator<helpers::iterator_to_allocator_t<input_iterator_t>>>
1622 dictionary(input_iterator_t, input_iterator_t,
xtd::size = 0, hasher_t = hasher_t {}, equator_t = equator_t {}, allocator_t = allocator_t {}) -> dictionary<helpers::iterator_key_t<input_iterator_t>, helpers::iterator_mapped_t<input_iterator_t>, hasher_t, equator_t, allocator_t>;
1624 template<
class input_iterator_t,
class allocator_t>
1625 dictionary(input_iterator_t, input_iterator_t,
xtd::size, allocator_t) -> dictionary<helpers::iterator_key_t<input_iterator_t>, helpers::iterator_mapped_t<input_iterator_t>, helpers::hasher<helpers::iterator_key_t<input_iterator_t>>, helpers::equator<helpers::iterator_key_t<input_iterator_t>>, allocator_t>;
1627 template<
class input_iterator_t,
class allocator_t>
1628 dictionary(input_iterator_t, input_iterator_t, allocator_t) -> dictionary<helpers::iterator_key_t<input_iterator_t>, helpers::iterator_mapped_t<input_iterator_t>, helpers::hasher<helpers::iterator_key_t<input_iterator_t>>, helpers::equator<helpers::iterator_key_t<input_iterator_t>>, allocator_t>;
1630 template<
class input_iterator_t,
class hasher_t,
class allocator_t>
1631 dictionary(input_iterator_t, input_iterator_t,
xtd::size, hasher_t, allocator_t) -> dictionary<helpers::iterator_key_t<input_iterator_t>, helpers::iterator_mapped_t<input_iterator_t>, hasher_t, helpers::equator<helpers::iterator_key_t<input_iterator_t>>, allocator_t>;
Contains xtd::collections::generic::helpers::allocator alias.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::array::begin(),...
Definition basic_array.hpp:229
Represents text as a sequence of character units.
Definition basic_string.hpp:71
static basic_string join(const basic_string separator, const collection_t &values) noexcept
Concatenates a specified separator basic_string between each element of a specified object array,...
Definition basic_string.hpp:2288
Provides a base class for implementations of the xtd::collections::generic::icomparer <type_t> generi...
Definition comparer.hpp:33
Represents a collection of keys and values.
Definition dictionary.hpp:67
void trim_excess(size_type capacity)
Sets the capacity of this dictionary to hold up a specified number of entries without any further exp...
Definition dictionary.hpp:1380
void merge(std::unordered_map< key_t, value_t, source_hasher_t, source_equator_t, allocator_t > &&source)
Splices nodes from another container.
Definition dictionary.hpp:1297
iterator erase(const_iterator pos)
Erases elements.
Definition dictionary.hpp:938
size_type max_size() const noexcept
Gets the maximum number of elements the container is able to hold due to system or library implementa...
Definition dictionary.hpp:657
const xtd::object & sync_root() const noexcept override
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
Definition dictionary.hpp:687
dictionary(dictionary &&other) noexcept=default
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
typename base_type::node_type node_type
Represents the dictionary node type.
Definition dictionary.hpp:177
iterator try_emplace(const_iterator hint, const key_t &k, args_t &&... args)
Inserts in-place if the key does not exist, does nothing if the key exists.
Definition dictionary.hpp:1441
bool remove(const key_t &key, value_t &value) noexcept
Removes the value with the specified key from the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:1349
local_iterator end(size_type n)
Returns an iterator to the end of the specified bucket.
Definition dictionary.hpp:873
dictionary(std::initializer_list< base_value_type > init, size_type bucket_count, const hasher_t &hash, const allocator_type &alloc)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:491
const value_t & operator[](const key_t &key) const override
Gets the element with the specified key.
Definition dictionary.hpp:1531
dictionary(std::initializer_list< key_value_pair< init_key_t, init_value_t > > init, size_type bucket_count, const hasher_t &hash, const allocator_type &alloc)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:539
hasher hash_function() const
Returns function used to hash the keys.
Definition dictionary.hpp:1069
dictionary(std::unordered_map< key_t, value_t > &&other) noexcept
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:446
const_iterator find(const key_t &key) const
Finds element with specific key.
Definition dictionary.hpp:992
key_value_pair< iterator, bool > insert(type_t &&value)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1103
iterator insert(const_iterator hint, value_type &&value)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1126
value_type & reference
Represents the dictionary reference type.
Definition dictionary.hpp:161
typename xtd::collections::generic::idictionary< key_type, mapped_type >::value_type value_type
Represents the dictionary value type.
Definition dictionary.hpp:147
insert_return_type insert(node_type &&nh)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1185
void add(const value_type &item) override
Adds an item to the xtd::collections::generic::icollection <type_t>.
Definition dictionary.hpp:717
node_type extract(const key_t k)
Extracts nodes from the container.
Definition dictionary.hpp:983
size_type capacity() const noexcept
Gets the total numbers of elements the internal data structure can hold without resizing.
Definition dictionary.hpp:563
key_value_pair< iterator, bool > insert(const value_type &value)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1079
typename base_type::const_local_iterator const_local_iterator
Represents the const local iterator of dictionary value type.
Definition dictionary.hpp:175
key_value_pair< iterator, bool > try_emplace(key_t &&k, args_t &&... args)
Inserts in-place if the key does not exist, does nothing if the key exists.
Definition dictionary.hpp:1427
dictionary(const std::unordered_map< key_t, value_t > &other)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:414
const iequality_comparer< key_t > & comparer() const noexcept
Gets the td::collections::generic::iequality_comparer <type_t> that is used to determine equality of ...
Definition dictionary.hpp:576
iterator insert_or_assign(const_iterator hint, key_t &&k, type_t &&obj)
Inserts an element or assigns to the current element if the key already exists.
Definition dictionary.hpp:1250
dictionary(const ienumerable< value_type > &collection, const equality_comparer_t &comparer)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that c...
Definition dictionary.hpp:313
void insert(std::initializer_list< base_value_type > ilist)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1162
const_local_iterator cbegin(size_type n) const
Returns an iterator to the beginning of the specified bucket.
Definition dictionary.hpp:774
value_t & at(const key_t &key)
Gets the element with the specified key.
Definition dictionary.hpp:738
dictionary(size_t capacity, const equality_comparer_t &comparer)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that i...
Definition dictionary.hpp:329
iterator insert(const_iterator hint, const value_type &value)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1115
size_type bucket(const key_t &key) const
Returns the index of the bucket for key key. Elements (if any) with keys equivalent to key are always...
Definition dictionary.hpp:763
void copy_to(xtd::array< value_type > &array, xtd::size array_index) const override
Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array,...
Definition dictionary.hpp:833
void reserve(size_type count)
Reserves space for at least the specified number of elements and regenerates the hash table.
Definition dictionary.hpp:1359
void swap(dictionary &other) noexcept
Swaps the contents.
Definition dictionary.hpp:1367
dictionary(std::initializer_list< base_value_type > init, size_type bucket_count=0, const hasher_t &hash=hasher_t {}, const equator_t &equal=equator_t {}, const allocator_type &alloc=allocator_type {})
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:462
dictionary(input_iterator_t first, input_iterator_t last, size_type bucket_count, const hasher_t &hash, const allocator_type &alloc)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:382
xtd::size ensure_capacity(xtd::size capacity) noexcept
Ensures that the dictionary can hold up to a specified number of entries without any further expansio...
Definition dictionary.hpp:888
std::unordered_map< key_type, mapped_type, hasher, key_equal, allocator_type > base_type
Represents the dictionary base type.
Definition dictionary.hpp:159
typename xtd::collections::generic::idictionary< key_type, mapped_type >::key_collection key_collection
Represents the idictionary key collection type.
Definition dictionary.hpp:181
key_value_pair< iterator, bool > insert(value_type &&value)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1090
const_iterator find(const find_key_t &x) const
Finds element with specific key.
Definition dictionary.hpp:1009
void clear() noexcept override
Removes all keys and values from the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:788
dictionary() noexcept=default
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that i...
iterator erase(const_iterator first, const_iterator last)
Erases elements.
Definition dictionary.hpp:950
dictionary(const std::unordered_map< key_t, value_t > &other, const allocator_type &alloc)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:428
bool empty() const noexcept
Checks if the container has no elements, i.e. whether begin() == end().
Definition dictionary.hpp:590
bool try_add(const key_t &key, const value_t value) noexcept
Attempts to add the specified key and value to the dictionary.
Definition dictionary.hpp:1400
const value_t & at(const key_t &key) const
Gets the element with the specified key.
Definition dictionary.hpp:727
typename xtd::collections::generic::idictionary< key_type, mapped_type >::value_collection value_collection
Represents the idictionary value collection type.
Definition dictionary.hpp:183
bool remove(const value_type &item) noexcept override
Removes the first occurrence of a specific object from the xtd::collections::generic::dictionary <key...
Definition dictionary.hpp:1341
void merge(dictionary< key_t, value_t, source_hasher_t, source_equator_t, allocator_t > &&source)
Splices nodes from another container.
Definition dictionary.hpp:1277
iterator insert(const_iterator hint, node_type &&nh)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1197
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition dictionary.hpp:550
key_value_pair< const_iterator, const_iterator > equal_range(const key_t &x) const
Returns range of elements matching a specific key.
Definition dictionary.hpp:926
key_value_pair< iterator, bool > emplace(args_t &&...args)
Constructs element in-place.
Definition dictionary.hpp:849
dictionary(std::unordered_map< key_t, value_t > &&other, const allocator_type &alloc) noexcept
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:451
key_equal key_eq() const
Returns the function used to compare keys for equality.
Definition dictionary.hpp:1258
iterator emplace_hint(iterator hint, args_t &&...args)
constructs elements in-place using a hint
Definition dictionary.hpp:864
std::pair< const key_t, value_t > base_value_type
Represents the dictionary base value type.
Definition dictionary.hpp:157
iterator find(const find_key_t &x)
Finds element with specific key.
Definition dictionary.hpp:1017
iterator insert(const_iterator hint, type_t &&value)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1139
key_value_pair< iterator, iterator > equal_range(const key_t &key)
Returns range of elements matching a specific key.
Definition dictionary.hpp:897
bool remove(const key_t &key) noexcept override
Removes the value with the specified key from the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:1334
void rehash(size_type count)
Reserves at least the specified number of buckets and regenerates the hash table.
Definition dictionary.hpp:1326
const_local_iterator begin(size_type n) const
Returns an iterator to the beginning of the specified bucket.
Definition dictionary.hpp:756
dictionary(input_iterator_t first, input_iterator_t last, size_type bucket_count=0, const hasher_t &hash=hasher_t {}, const equator_t &equal=equator_t {}, const allocator_type &alloc=allocator_type {})
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:351
node_type extract(const_iterator position) noexcept
Extracts nodes from the container.
Definition dictionary.hpp:973
typename xtd::collections::generic::idictionary< key_type, mapped_type >::const_iterator const_iterator
Represents the const iterator of dictionary value type.
Definition dictionary.hpp:171
bool contains(const key_t &key) const noexcept
Checks if the container contains element with specific key.
Definition dictionary.hpp:795
void trim_excess()
Sets the capacity of this dictionary to what it would be if it had been originally initialized with a...
Definition dictionary.hpp:1391
typename base_type::insert_return_type insert_return_type
Represents the dictionary insert return type.
Definition dictionary.hpp:179
dictionary & operator=(dictionary &&other) noexcept
Move assignment operator. Replaces the contents with a copy of the contents of other.
Definition dictionary.hpp:1480
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition dictionary.hpp:594
void insert(input_iterator_t first, input_iterator_t last)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1151
typename std::allocator_traits< allocator_t >::pointer pointer
Represents the dictionary pointer type.
Definition dictionary.hpp:165
dictionary(input_iterator_t first, input_iterator_t last, size_type bucket_count, const allocator_type &alloc)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:366
key_value_pair< const_iterator, const_iterator > equal_range(const equal_range_key_t &key) const
Returns range of elements matching a specific key.
Definition dictionary.hpp:907
dictionary(std::initializer_list< key_value_pair< init_key_t, init_value_t > > init, size_type bucket_count, const allocator_type &alloc)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:523
size_type bucket_size(size_type n) const noexcept
Returns the number of elements in the bucket with index n.
Definition dictionary.hpp:768
local_iterator begin(size_type n)
Returns an iterator to the beginning of the specified bucket.
Definition dictionary.hpp:748
iterator end() noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition dictionary.hpp:598
void add(const key_t &key, const value_t value) override
Adds an element with the provided key and value to the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:710
bool contains(const value_type &item) const noexcept override
Determines whether an element is in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:809
dictionary(size_type bucket_count, const hasher_t &hash, const allocator_type &alloc) noexcept
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:289
key_value_pair< iterator, iterator > equal_range(const equal_range_key_t &x)
Returns range of elements matching a specific key.
Definition dictionary.hpp:917
bool is_synchronized() const noexcept override
Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is sync...
Definition dictionary.hpp:619
size_type size() const noexcept
Gets the number of key/value pairs contained in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:664
iterator try_emplace(const_iterator hint, key_t &&k, args_t &&... args)
Inserts in-place if the key does not exist, does nothing if the key exists.
Definition dictionary.hpp:1454
const_local_iterator end(size_type n) const
Returns an iterator to the end of the specified bucket.
Definition dictionary.hpp:881
value_collection values() const noexcept override
Gets a collection containing the values in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:693
void merge(dictionary< key_t, value_t, source_hasher_t, source_equator_t, allocator_t > &source)
Splices nodes from another container.
Definition dictionary.hpp:1267
size_type erase(const key_t &key)
Erases elements.
Definition dictionary.hpp:961
dictionary(const dictionary &other) noexcept
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:394
void insert(std::initializer_list< key_value_pair< init_key_t, init_value_t > > ilist)
Inserts element(s) into the container, if the container doesn't already contain an element with an eq...
Definition dictionary.hpp:1172
dictionary(dictionary &&other, const allocator_type &alloc) noexcept
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:442
const_local_iterator cend(size_type n) const
Returns an iterator to the end of the specified bucket.
Definition dictionary.hpp:782
void merge(std::unordered_map< key_t, value_t, source_hasher_t, source_equator_t, allocator_t > &source)
Splices nodes from another container.
Definition dictionary.hpp:1287
dictionary(const idictionary< key_t, value_t > &dictionary, const equality_comparer_t &comparer)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that c...
Definition dictionary.hpp:302
typename xtd::collections::generic::idictionary< key_t, value_t >::mapped_type mapped_type
Represents the dictionary mapped type.
Definition dictionary.hpp:145
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:1027
bool contains(const contains_key_t &x) const
Checks if the container contains element with specific key.
Definition dictionary.hpp:802
key_collection keys() const noexcept override
Gets a collection containing the keys in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:632
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition dictionary.hpp:567
typename xtd::collections::generic::idictionary< key_t, value_t >::key_type key_type
Represents the dictionary key type.
Definition dictionary.hpp:143
virtual const base_type & items() const noexcept
Returns the underlying base type items.
Definition dictionary.hpp:623
void merge(std::unordered_multimap< key_t, value_t, source_hasher_t, source_equator_t, allocator_t > &source)
Splices nodes from another container.
Definition dictionary.hpp:1307
bool try_get_value(const key_t &key, value_t &value) const override
Gets the value associated with the specified key.
Definition dictionary.hpp:1463
key_value_pair< iterator, bool > insert_or_assign(key_t &&k, type_t &&obj)
Inserts an element or assigns to the current element if the key already exists.
Definition dictionary.hpp:1223
dictionary(const equality_comparer_t &comparer)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that i...
Definition dictionary.hpp:251
dictionary(std::initializer_list< base_value_type > init, size_type bucket_count, const allocator_type &alloc)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:476
bool contains_key(const key_t &key) const noexcept override
Determines whether the xtd::collections::generic::dictionary <key_t, value_t> contains the specified ...
Definition dictionary.hpp:819
float load_factor() const
Gets the average number of elements per bucket, that is, xtd::collections::generic::dictionary::size ...
Definition dictionary.hpp:641
allocator_t allocator_type
Represents the dictionary allocator type.
Definition dictionary.hpp:155
void merge(std::unordered_multimap< key_t, value_t, source_hasher_t, source_equator_t, allocator_t > &&source)
Splices nodes from another container.
Definition dictionary.hpp:1317
iterator begin() noexcept override
Returns an iterator to the first element of the enumarable.
Definition dictionary.hpp:553
size_type bucket_count() const noexcept
Gets the number of buckets in the container.
Definition dictionary.hpp:558
const_iterator cend() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition dictionary.hpp:571
xtd::ptrdiff difference_type
Represents the dictionary difference type.
Definition dictionary.hpp:151
void max_load_factor(float value) const
Sets the maximum load factor (number of elements per bucket). The container automatically increases t...
Definition dictionary.hpp:652
const value_type & const_reference
Represents the dictionary const reference type.
Definition dictionary.hpp:163
key_value_pair< iterator, bool > insert_or_assign(const key_t &k, type_t &&obj)
Inserts an element or assigns to the current element if the key already exists.
Definition dictionary.hpp:1210
size_type max_bucket_count() const noexcept
Gets the maximum number of buckets the container is able to hold due to system or library implementat...
Definition dictionary.hpp:645
typename base_type::local_iterator local_iterator
Represents the local iterator of dictionary value type.
Definition dictionary.hpp:173
iterator insert_or_assign(const_iterator hint, const key_t &k, type_t &&obj)
Inserts an element or assigns to the current element if the key already exists.
Definition dictionary.hpp:1237
const_iterator find(const key_t &key)
Finds element with specific key.
Definition dictionary.hpp:1000
allocator_type get_allocator() const noexcept
Returns the allocator associated with the container.
Definition dictionary.hpp:1023
dictionary(size_type bucket_count, const hasher_t &hash=hasher_t {}, const equator_t &equal=equator_t {}, const allocator_type &alloc=allocator_type {}) noexcept
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:264
dictionary(const ienumerable< value_type > &collection)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that c...
Definition dictionary.hpp:240
xtd::string to_string() const noexcept override
Gets a string that represents the current object.
Definition dictionary.hpp:1374
virtual base_type & items() noexcept
Returns the underlying base type items.
Definition dictionary.hpp:626
typename xtd::collections::generic::idictionary< key_type, mapped_type >::iterator iterator
Represents the iterator of dictionary value type.
Definition dictionary.hpp:169
bool is_read_only() const noexcept override
Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
Definition dictionary.hpp:603
key_value_pair< iterator, bool > try_emplace(const key_t &k, args_t &&... args)
Inserts in-place if the key does not exist, does nothing if the key exists.
Definition dictionary.hpp:1414
float max_load_factor() const
Gets the maximum load factor (number of elements per bucket). The container automatically increases t...
Definition dictionary.hpp:649
xtd::size size_type
Represents the dictionary size type.
Definition dictionary.hpp:149
typename std::allocator_traits< allocator_t >::const_pointer const_pointer
Represents the dictionary const pointer type.
Definition dictionary.hpp:167
dictionary(std::initializer_list< key_value_pair< init_key_t, init_value_t > > init, size_type bucket_count=0, const hasher_t &hash=hasher_t {}, const equator_t &equal=equator_t {}, const allocator_type &alloc=allocator_type {})
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:508
size_type count() const noexcept override
Gets the number of key/value pairs contained in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:586
static const equality_comparer & default_equality_comparer()
Gets the default equality comparer for the type specified by the generic argument.
Definition equality_comparer.hpp:42
static target_collection_t::const_iterator to_iterator(typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept
Converts source iterator to target iterator.
Definition enumerable_iterators.hpp:188
virtual const_iterator begin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.hpp:155
virtual const_iterator cbegin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.hpp:162
virtual const_iterator cend() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.hpp:166
Represents a generic collection of key/value pairs.
Definition idictionary.hpp:44
typename xtd::collections::generic::icollection< value_type >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition idictionary.hpp:58
typename xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > >::value_type value_type
Represents the xtd::collections::generic::idictionary value type.
Definition idictionary.hpp:54
key_t key_type
Represents the dictionary key type.
Definition idictionary.hpp:50
typename xtd::collections::generic::icollection< value_type >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition idictionary.hpp:56
value_t mapped_type
Represents the dictionary mapped type.
Definition idictionary.hpp:52
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
Defines methods to support the comparison of objects for equality.
Definition iequality_comparer.hpp:34
Represents a collection of objects that can be individually accessed by index.
Definition ilist.hpp:41
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:43
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
virtual xtd::size get_hash_code() const noexcept
Serves as a hash function for a particular type.
The xtd::shared_ptr_object is a shared pointer as std::shared_ptr.
Definition shared_ptr_object.hpp:30
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:114
Contains xtd::collections::generic::helpers::equator struct.
xtd::collections::generic::comparer< xtd::any_object > comparer
Exposes a method that compares two objects.
Definition comparer.hpp:25
@ argument
The argument is not valid.
@ argument_out_of_range
The argument is out of range.
@ invalid_operation
The operation is not valid.
@ key_not_found
The key is not found.
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.hpp:23
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
@ other
The operating system is other.
@ insert
The INS (INSERT) key.
Contains xtd::collections::generic::helpers::hasher struct.
Contains xtd::collections::idictionary alias.
Contains iteraors aliases.
Contains xtd::collections::key_not_found_exception exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Represents the dictionary equator type.
Definition dictionary.hpp:104
bool operator()(const key_t &a, const key_t &b) const
checks if the specified a and b keys are equal.
Definition dictionary.hpp:124
key_t first_argument_type
Represents the first argument type.
Definition dictionary.hpp:109
bool result_type
Represents the result type.
Definition dictionary.hpp:113
key_t second_argument_type
Represents the second argument type.
Definition dictionary.hpp:111
Represents the dictionary hasher type.
Definition dictionary.hpp:73
key_t argument_type
Represents the argument type.
Definition dictionary.hpp:78
xtd::size result_type
Represents the result type.
Definition dictionary.hpp:80
size_t operator()(const key_t &key) const
Serves as a hash function for a specified key with a particular type (type_t).
Definition dictionary.hpp:90
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37