xtd 0.2.0
dictionary.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "helpers/equator.hpp"
7#include "helpers/hasher.hpp"
9#include "idictionary.hpp"
12#include "../../new_ptr.hpp"
13#include "../../ptr.hpp"
14#include <cmath>
15#include <unordered_map>
16
18namespace xtd {
20 namespace collections {
22 namespace generic {
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 >>>
67 class dictionary : public xtd::object, public xtd::collections::generic::idictionary<key_t, value_t> {
68 public:
70
73 struct hasher {
75
78 using argument_type = key_t;
82
84
90 size_t operator()(const key_t& key) const {
91 if (comparer) return comparer->get_hash_code(key);
92 return hasher_t {}(key);
93 }
94
95
96private:
97 friend class dictionary;
98 hasher() = default;
100 const iequality_comparer<key_t>* comparer = nullptr;
101 };
102
104 struct equator {
106
109 using first_argument_type = key_t;
111 using second_argument_type = key_t;
113 using result_type = bool;
115
117
124 bool operator()(const key_t & a, const key_t & b) const {
125 if (&a == &b) return true;
126 if (comparer) return comparer->equals(a, b);
127 return equator_t {}(a, b);
128 }
129
130
131private:
132 friend class dictionary;
133 equator() = default;
134 explicit equator(const iequality_comparer < key_t > * comparer) : comparer {comparer} {}
135 const iequality_comparer < key_t > * comparer = nullptr;
136 };
137
138
140
155 using allocator_type = allocator_t;
157 using base_value_type = std::pair < const key_t, value_t >;
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;
173 using local_iterator = typename base_type::local_iterator;
175 using const_local_iterator = typename base_type::const_local_iterator;
177 using node_type = typename base_type::node_type;
179 using insert_return_type = typename base_type::insert_return_type;
185
187
219 dictionary() noexcept = default;
220
231 dictionary(const idictionary < key_t, value_t > & dictionary) {
233 for (const auto& item : dictionary)
234 add(item);
235 }
236
241 for (const auto& item : collection)
242 add(item);
243 }
244
250 template < class equality_comparer_t >
251 dictionary(const equality_comparer_t& comparer) : data_(xtd::new_ptr < data > (new_ptr < equality_comparer_t > (comparer))) {}
252
264 explicit dictionary(size_type bucket_count, const hasher_t& hash = hasher_t {}, const equator_t& equal = equator_t {}, const allocator_type& alloc = allocator_type {}) noexcept : data_(xtd::new_ptr < data > (bucket_count)) {}
265
266 /* Confict with dictionary(size_t capacity, const equality_comparer_t& comparer) constructor
276 dictionary(size_type bucket_count, const allocator_type& alloc) noexcept : data_(xtd::new_ptr<data>(bucket_count)) {}
277 */
278
289 dictionary(size_type bucket_count, const hasher_t& hash, const allocator_type & alloc) noexcept : data_(xtd::new_ptr < data > (bucket_count)) {}
290
301 template < class equality_comparer_t >
302 dictionary(const idictionary < key_t, value_t > & dictionary, const equality_comparer_t& comparer) : data_(xtd::new_ptr < data>(new_ptr < equality_comparer_t > (comparer))) {
304 for (const auto& item : dictionary)
305 add(item);
306 }
307
312 template < class equality_comparer_t >
313 dictionary(const ienumerable < value_type > & collection, const equality_comparer_t& comparer) : data_(xtd::new_ptr < data>(new_ptr < equality_comparer_t > (comparer))) {
314 for (const auto& item : collection)
315 add(item);
316 }
317
328 template < class equality_comparer_t >
329 dictionary(size_t capacity, const equality_comparer_t& comparer) : data_(xtd::new_ptr < data > (new_ptr < equality_comparer_t > (comparer))) {
331 }
332
333 /* Conflict with dictionary(const equality_comparer_t& comparer) constructor.
337 explicit dictionary(const allocator_t& alloc) noexcept {}
338 */
339
350 template < class input_iterator_t >
351 explicit 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 {}) : data_(xtd::new_ptr < data > (bucket_count)) {
352 for (auto iterator = first; iterator != last; ++iterator) {
353 const auto& [key, value] = *iterator;
354 add(key, value);
355 }
356 }
357
365 template < class input_iterator_t >
366 explicit dictionary(input_iterator_t first, input_iterator_t last, size_type bucket_count, const allocator_type & alloc) : data_(xtd::new_ptr < data > (bucket_count)) {
367 for (auto iterator = first; iterator != last; ++iterator) {
368 const auto& [key, value] = *iterator;
369 add(key, value);
370 }
371 }
372
381 template < class input_iterator_t >
382 explicit dictionary(input_iterator_t first, input_iterator_t last, size_type bucket_count, const hasher_t& hash, const allocator_type & alloc) : data_(xtd::new_ptr < data > (bucket_count)) {
383 for (auto iterator = first; iterator != last; ++iterator) {
384 const auto& [key, value] = *iterator;
385 add(key, value);
386 }
387 }
388
394 dictionary(const dictionary & other) noexcept : data_(xtd::new_ptr < data > (other.data_->comparer, other.data_->items, other.data_->version)) {}
395
396 /* Conflict with dictionary(const idictionary<key_t, value_t>& dictionary, const equality_comparer_t& comparer) constructor.
404 dictionary(const dictionary& other, const allocator_type& alloc) noexcept : data_(xtd::new_ptr<data>(other.data_->comparer, other.data_->items, other.data_->version)) {}
405 */
406
414 dictionary(const std::unordered_map < key_t, value_t > & other) {
415 for (auto iterator = other.begin(); iterator != other.end(); ++iterator) {
416 const auto& [key, value] = *iterator;
417 add(key, value);
418 }
419 }
420
428 dictionary(const std::unordered_map < key_t, value_t > & other, const allocator_type & alloc) {
429 for (auto iterator = other.begin(); iterator != other.end(); ++iterator) {
430 const auto& [key, value] = *iterator;
431 add(key, value);
432 }
433 }
434
437 dictionary(dictionary&& other) noexcept = default;
442 dictionary(dictionary&& other, const allocator_type & alloc) noexcept : data_(xtd::new_ptr < data > (std::move(other.data_->items), other.data_->version)) {}
446 dictionary(std::unordered_map < key_t, value_t > && other) noexcept : data_(xtd::new_ptr < data>(std::move(other.data_->items))) {}
451 dictionary(std::unordered_map < key_t, value_t > && other, const allocator_type & alloc) noexcept : data_(xtd::new_ptr < data>(std::move(other.data_->items))) {}
462 explicit 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 {}) : data_(xtd::new_ptr < data > (bucket_count)) {
463 for (const auto& [key, value] : init) {
465 (*this)[key] = value;
466 }
467 }
468
478 dictionary(std::initializer_list < base_value_type > init, size_type bucket_count, const allocator_type & alloc) : data_(xtd::new_ptr < data > (bucket_count)) {
479 for (const auto& [key, value] : init) {
481 (*this)[key] = value;
482 }
483 }
484
495 dictionary(std::initializer_list < base_value_type > init, size_type bucket_count, const hasher_t& hash, const allocator_type & alloc) : data_(xtd::new_ptr < data > (bucket_count)) {
496 for (const auto& [key, value] : init) {
498 (*this)[key] = value;
499 }
500 }
501
513 template < class init_key_t, class init_value_t >
514 explicit 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 {}) : data_(xtd::new_ptr < data > (bucket_count)) {
515 for (const auto& [key, value] : init) {
517 (*this)[key] = value;
518 }
519 }
520
530 template < class init_key_t, class init_value_t >
531 dictionary(std::initializer_list < key_value_pair < init_key_t, init_value_t>> init, size_type bucket_count, const allocator_type & alloc) : data_(xtd::new_ptr < data > (bucket_count)) {
532 for (const auto& [key, value] : init) {
534 (*this)[key] = value;
535 }
536 }
537
548 template < class init_key_t, class init_value_t >
549 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) : data_(xtd::new_ptr < data > (bucket_count)) {
550 for (const auto& [key, value] : init) {
552 (*this)[key] = value;
553 }
554 }
555
556
558
562 const_iterator begin() const noexcept override {return ienumerable < value_type >::begin();}
565 iterator begin() noexcept override {return ienumerable < value_type >::begin();}
566
570 size_type bucket_count() const noexcept {return data_->items.bucket_count();}
571
575 size_type capacity() const noexcept {return bucket_count();}
576
579 const_iterator cbegin() const noexcept override {return ienumerable < value_type >::cbegin();}
580
583 const_iterator cend() const noexcept override {return ienumerable < value_type >::cend();}
584
588 const iequality_comparer < key_t > & comparer() const noexcept {
589 if (data_->comparer) return *data_->comparer;
591 }
592
598 size_type count() const noexcept override {return data_->items.size();}
599
602 bool empty() const noexcept {return data_->items.empty();}
603
606 const_iterator end() const noexcept override {return ienumerable < value_type >::cend();}
607
610 iterator end() noexcept override {return ienumerable < value_type >::end();}
611
615 bool is_read_only() const noexcept override {return false;}
616
631 bool is_synchronized() const noexcept override {return false;}
632
635 virtual const base_type & items() const noexcept {return data_->items;}
638 virtual base_type & items() noexcept {return data_->items;}
639
644 key_collection keys() const noexcept override {
645 auto keys = key_collection {};
646 for (const auto& [key, value] : data_->items)
647 keys.add(key);
648 return keys;
649 }
650
653 float load_factor() const {return data_->items.load_factor();}
654
657 size_type max_bucket_count() const noexcept {return data_->items.max_bucket_count();}
658
661 float max_load_factor() const {return data_->items.max_load_factor();}
664 void max_load_factor(float value) const {data_->items.max_load_factor(value);}
665
669 size_type max_size() const noexcept {return data_->items.max_size();}
670
676 size_type size() const noexcept {return data_->items.size();}
677
699 const xtd::object & sync_root() const noexcept override {return data_->sync_root;}
700
705 value_collection values() const noexcept override {
706 auto values = value_collection {};
707 for (const auto& [key, value] : data_->items)
708 values.add(value);
709 return values;
710 }
711
712
714
722 void add(const key_t & key, const value_t value) override {
724 }
725
729 void add(const value_type & item) override {
730 add(item.key(), item.value());
731 }
732
733
739 const value_t& at(const key_t & key) const {
740 auto iterator = data_->items.find(key);
742 return iterator->second;
743 }
744
750 value_t& at(const key_t & key) {
751 auto iterator = data_->items.find(key);
753 return iterator->second;
754 }
755
761 return data_->items.begin(n);
762 }
763
769 return data_->items.begin(n);
770 }
771
775 size_type bucket(const key_t & key) const {return data_->items.bucket(key);}
776
780 size_type bucket_size(size_type n) const noexcept {return data_->items.bucket_size(n);}
781
787 return data_->items.begin(n);
788 }
789
795 return data_->items.end(n);
796 }
797
800 void clear() noexcept override {
801 data_->items.clear();
802 ++data_->version;
803 }
804
807 bool contains(const key_t & key) const noexcept {
808 return data_->items.find(key) != data_->items.end();
809 }
810
813 template < class contains_key_t >
814 bool contains(const contains_key_t& x) const {
815 return data_->items.find(x) != data_->items.end();
816 }
817
821 bool contains(const value_type & item) const noexcept override {
822 auto iterator = find(item.key());
823 if (iterator == end()) return false;
824 return iterator->value() == item.value();
825 }
826
831 bool contains_key(const key_t & key) const noexcept override {
832 return contains(key);
833 }
834
835 bool contains_value(const value_t& value) const noexcept {
836 for (const auto& [item_key, item_value] : *this)
837 if (item_value == value) return true;
838 return false;
839 }
840
845 void copy_to(xtd::array < value_type > & array, xtd::size array_index) const override {
847 auto index = size_type {0};
848 for (const auto& item : *this)
849 array[array_index + index++] = item;
850 }
851
860 template < class ...args_t >
861 key_value_pair < iterator, bool > emplace(args_t&& ...args) {
862 const auto& [iterator, succeeded] = data_->items.emplace(std::forward < args_t > (args)...);
863 if (succeeded) ++data_->version;
864 return {to_type_iterator(iterator), succeeded};
865 }
866
875 template < class ...args_t >
876 iterator emplace_hint(iterator hint, args_t&& ...args) {
877 ++data_->version;
878 return to_type_iterator(data_->items.emplace_hint(to_base_type_iterator(hint), std::forward < args_t > (args)...));
879 }
880
886 return data_->items.end(n);
887 }
888
894 return data_->items.end(n);
895 }
896
901 data_->items.reserve(capacity);
902 return this->capacity();
903 }
904
909 key_value_pair < iterator, iterator > equal_range(const key_t & key) {
910 const auto& [first, last] = data_->items.equal_range(key);
911 return {to_type_iterator(first), to_type_iterator(last)};
912 }
913
918 template < class equal_range_key_t >
919 key_value_pair < const_iterator, const_iterator > equal_range(const equal_range_key_t& key) const {
920 const auto& [first, last] = data_->items.equal_range(key);
921 return {to_const_type_iterator(first), to_const_type_iterator(last)};
922 }
923
928 template < class equal_range_key_t >
929 key_value_pair < iterator, iterator > equal_range(const equal_range_key_t& x) {
930 const auto& [first, last] = data_->items.equal_range(x);
931 return {to_type_iterator(first), to_type_iterator(last)};
932 }
933
938 key_value_pair < const_iterator, const_iterator > equal_range(const key_t & x) const {
939 const auto& [first, last] = data_->items.equal_range(x);
940 return {to_const_type_iterator(first), to_const_type_iterator(last)};
941 }
942
951 ++data_->version;
952 return to_type_iterator(data_->items.erase(to_const_base_type_iterator(pos)));
953 }
954
963 ++data_->version;
964 return to_type_iterator(data_->items.erase(to_const_base_type_iterator(first), to_const_base_type_iterator(last)));
965 }
966
973 size_type erase(const key_t & key) {
974 auto removed_count = data_->items.erase(key);
975 if (removed_count) ++data_->version;
976 return removed_count;
977 }
978
985 node_type extract(const_iterator position) noexcept {
986 ++data_->version;
987 return data_->items.extract(to_const_base_type_iterator(position));
988 }
989
995 node_type extract(const key_t k) {
996 ++data_->version;
997 return data_->items.extract(k);
998 }
999
1004 const_iterator find(const key_t & key) const {
1005 return to_const_type_iterator(data_->items.find(key));
1006 }
1007
1012 iterator find(const key_t & key) {
1013 return to_type_iterator(data_->items.find(key));
1014 }
1015
1020 template < class find_key_t >
1021 const_iterator find(const find_key_t& x) const {
1022 return to_const_type_iterator(data_->items.find(x));
1023 }
1024
1028 template < class find_key_t >
1029 iterator find(const find_key_t& x) {
1030 return to_type_iterator(data_->items.find(x));
1031 }
1032
1035 allocator_type get_allocator() const noexcept {return data_->items.get_allocator();}
1036
1039 enumerator < value_type > get_enumerator() const noexcept override {
1040 struct internal_enumerator : public ienumerator < value_type > {
1041 public:
1042 explicit internal_enumerator(const dictionary & items, size_type version) : items_(items), version_(version) {}
1043
1044 const value_type & current() const override {
1045 if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
1046 if (iterator_ != items_.items().cend()) {
1047 static thread_local auto value = value_type {};
1048 value = value_type {*iterator_};
1049 return value;
1050 }
1051 static auto default_value_type = value_type {};
1052 return default_value_type;
1053 }
1054
1055 bool move_next() override {
1056 if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
1057 if (!reset_) return ++iterator_ != items_.items().cend();
1058 reset_ = false;
1059 iterator_ = items_.items().cbegin();
1060 return iterator_ != items_.items().cend();
1061 }
1062
1063 void reset() override {
1064 reset_ = true;
1065 version_ = items_.data_->version;
1066 iterator_ = items_.items().cend();
1067 }
1068
1069protected:
1070 bool reset_ = true;
1071 const dictionary& items_;
1072 typename dictionary::base_type::const_iterator iterator_ = items_.items().cend();
1073 size_type version_ = 0;
1074 };
1075 return {new_ptr < internal_enumerator > (*this, data_->version)};
1076 }
1077
1081 hasher hash_function() const {
1082 return data_->items.hash_function();
1083 }
1084
1091 key_value_pair < iterator, bool > insert(const value_type & value) {
1092 const auto& [iterator, succeeded] = data_->items.insert(value);
1093 if (succeeded) ++data_->version;
1094 return {to_type_iterator(iterator), succeeded};
1095 }
1096
1102 key_value_pair < iterator, bool > insert(value_type&& value) {
1103 const auto& [iterator, succeeded] = data_->items.insert(value);
1104 if (succeeded) ++data_->version;
1105 return {to_type_iterator(iterator), succeeded};
1106 }
1107
1114 template < class type_t >
1115 key_value_pair < iterator, bool > insert(type_t&& value) {
1116 const auto& [iterator, succeeded] = data_->items.insert(value);
1117 if (succeeded) ++data_->version;
1118 return {to_type_iterator(iterator), succeeded};
1119 }
1120
1128 ++data_->version;
1129 return to_type_iterator(data_->items.insert(to_const_base_type_iterator(hint), value));
1130 }
1131
1139 ++data_->version;
1140 return to_type_iterator(data_->items.insert(to_const_base_type_iterator(hint), value));
1141 }
1142
1150 template < class type_t >
1151 iterator insert(const_iterator hint, type_t&& value) {
1152 ++data_->version;
1153 return to_type_iterator(data_->items.insert(to_const_base_type_iterator(hint), value));
1154 }
1155
1162 template < class input_iterator_t >
1163 void insert(input_iterator_t first, input_iterator_t last) {
1164 for (auto iterator = first; iterator != last; ++iterator) {
1165 const auto& [key, value] = *iterator;
1166 add(key, value);
1167 }
1168 }
1169
1174 void insert(std::initializer_list < base_value_type > ilist) {
1175 for (const auto& [key, value] : ilist)
1176 add(std::forward < value_type > ({key, value}));
1177 }
1178
1183 template < class init_key_t, class init_value_t >
1184 void insert(std::initializer_list < key_value_pair < init_key_t, init_value_t>> ilist) {
1185 for (const auto& [key, value] : ilist)
1186 add(std::forward < value_type > ({key, value}));
1187 }
1188
1198 ++data_->version;
1199 return data_->items.inser(nh);
1200 }
1201
1210 ++data_->version;
1211 return to_type_iterator(data_->items.inser(to_const_base_type_iterator(hint), nh));
1212 }
1213
1221 template < class type_t >
1222 key_value_pair < iterator, bool > insert_or_assign(const key_t & k, type_t&& obj) {
1223 const auto& [iterator, succeeded] = data_->items.insert_or_assign(k, obj);
1224 if (succeeded) ++data_->version;
1225 return {to_type_iterator(iterator), succeeded};
1226 }
1227
1234 template < class type_t >
1235 key_value_pair < iterator, bool > insert_or_assign(key_t&& k, type_t&& obj) {
1236 const auto& [iterator, succeeded] = data_->items.insert_or_assign(std::move(k), obj);
1237 if (succeeded) ++data_->version;
1238 return {to_type_iterator(iterator), succeeded};
1239 }
1240
1248 template < class type_t >
1249 iterator insert_or_assign(const_iterator hint, const key_t & k, type_t&& obj) {
1250 ++data_->version;
1251 return to_type_iterator(data_->items.insert_or_assign(to_const_base_type_iterator(hint), k, obj));
1252 }
1253
1261 template < class type_t >
1262 iterator insert_or_assign(const_iterator hint, key_t&& k, type_t&& obj) {
1263 ++data_->version;
1264 return to_type_iterator(data_->items.insert_or_assign(to_const_base_type_iterator(hint), std::move(k), obj));
1265 }
1266
1271 return data_->items.key_eq();
1272 }
1273
1278 template < class source_hasher_t, class source_equator_t >
1280 data_->items.merge(source.items);
1281 ++data_->version;
1282 }
1283
1288 template < class source_hasher_t, class source_equator_t >
1290 data_->items.merge(std::move(source.items));
1291 ++data_->version;
1292 }
1293
1298 template < class source_hasher_t, class source_equator_t >
1299 void merge(std::unordered_map < key_t, value_t, source_hasher_t, source_equator_t, allocator_t > & source) {
1300 data_->items.merge(source);
1301 ++data_->version;
1302 }
1303
1308 template < class source_hasher_t, class source_equator_t >
1309 void merge(std::unordered_map < key_t, value_t, source_hasher_t, source_equator_t, allocator_t > && source) {
1310 data_->items.merge(std::move(source));
1311 ++data_->version;
1312 }
1313
1318 template < class source_hasher_t, class source_equator_t >
1319 void merge(std::unordered_multimap < key_t, value_t, source_hasher_t, source_equator_t, allocator_t > & source) {
1320 data_->items.merge(source);
1321 ++data_->version;
1322 }
1323
1328 template < class source_hasher_t, class source_equator_t >
1329 void merge(std::unordered_multimap < key_t, value_t, source_hasher_t, source_equator_t, allocator_t > && source) {
1330 data_->items.merge(std::move(source));
1331 ++data_->version;
1332 }
1333
1339 data_->items.rehash(count);
1340 }
1341
1346 bool remove(const key_t & key) noexcept override {
1347 return erase(key) == 1;
1348 }
1349
1353 bool remove(const value_type & item) noexcept override {
1354 if (!contains_value(item.value())) return false;
1355 return erase(item.key()) == 1;
1356 }
1357
1361 bool remove(const key_t & key, value_t& value) noexcept {
1362 auto iterator = find(key);
1363 if (iterator == end()) return false;
1364 value = iterator->value();
1365 return erase(iterator) != end();
1366 }
1367
1372 data_->items.reserve(count);
1373 }
1374
1379 void swap(dictionary & other) noexcept {
1380 data_->items.swap(other.data_->items);
1381 std::swap(data_->version, other.data_->version);
1382 }
1383
1386 xtd::string to_string() const noexcept override {return xtd::string::format("{{{}}}", xtd::string::join(", ", *this));}
1387
1396
1404 rehash(count());
1405 }
1406
1412 bool try_add(const key_t & key, const value_t value) noexcept {
1413 const auto& [iterator, succeeded] = data_->items.insert(std::forward < base_value_type > ({key, value}));
1414 if (succeeded) ++data_->version;
1415 return succeeded;
1416 }
1417
1425 template < class ...args_t >
1426 key_value_pair < iterator, bool > try_emplace(const key_t & k, args_t&&... args) {
1427 const auto& [iterator, succeeded] = to_type_iterator(data_->items.try_emplace(k, std::forward < args_t > (args)...));
1428 if (succeeded) ++data_->version;
1429 return {to_type_iterator(iterator), succeeded};
1430 }
1431
1438 template < class ...args_t >
1439 key_value_pair < iterator, bool > try_emplace(key_t&& k, args_t&&... args) {
1440 const auto& [iterator, succeeded] = to_type_iterator(data_->items.try_emplace(std::move(k), std::forward < args_t > (args)...));
1441 if (succeeded) ++data_->version;
1442 return {to_type_iterator(iterator), succeeded};
1443 }
1444
1452 template < class ...args_t >
1453 iterator try_emplace(const_iterator hint, const key_t & k, args_t&&... args) {
1454 ++data_->version;
1455 return to_type_iterator(data_->items.try_emplace(to_const_base_type_iterator(hint), k, std::forward < args_t > (args)...));
1456 }
1457
1465 template < class ...args_t >
1466 iterator try_emplace(const_iterator hint, key_t&& k, args_t&&... args) {
1467 ++data_->version;
1468 return to_type_iterator(data_->items.try_emplace(to_const_base_type_iterator(hint), std::move(k), std::forward < args_t > (args)...));
1469 }
1470
1475 bool try_get_value(const key_t & key, value_t& value) const override {
1476 auto iterator = find(key);
1477 if (iterator != end()) {
1478 value = iterator->value();
1479 return true;
1480 }
1481 value = value_t {};
1482 return false;
1483 }
1484
1485
1487
1493 data_->comparer = std::move(other.data_->comparer);
1494 data_->items = std::move(other.data_->items);
1495 data_->version = std::move(other.data_->version);
1496 return *this;
1497 }
1498
1501 dictionary& operator =(std::unordered_map < key_t, value_t > && other) noexcept {
1502 data_->items = std::move(other);
1503 ++data_->version;
1504 return *this;
1505 }
1506
1509 dictionary& operator =(const dictionary & other) noexcept = default;
1513 dictionary& operator =(const std::unordered_map < key_t, value_t > & other) noexcept {
1514 data_->items.clear();
1515 for (const auto& [key, value] : other)
1516 add(key, value);
1517 }
1518
1521 dictionary& operator =(std::initializer_list < base_value_type > ilist) {
1522 data_->items.clear();
1523 for (const auto& [key, value] : ilist)
1524 add(key, value);
1525 }
1526
1529 template < class init_key_t, class init_value_t >
1530 dictionary& operator =(std::initializer_list < key_value_pair < init_key_t, init_value_t>> ilist) {
1531 data_->items.clear();
1532 for (const auto& [key, value] : ilist)
1533 add(key, value);
1534 }
1535
1543 const value_t& operator [](const key_t & key) const override {return at(key);}
1550 value_t& operator [](const key_t & key) override {
1551 ++data_->version;
1552 return data_->items[key];}
1553
1556 operator const base_type & () const noexcept {return data_->items;}
1559 operator base_type & () noexcept {return data_->items;}
1561
1562 private:
1563 typename base_type::const_iterator to_const_base_type_iterator(const_iterator value) const noexcept {
1564 return idictionary < key_t, value_t >::to_const_iterator(value, *this, data_->items);
1565 }
1566
1567 const_iterator to_const_type_iterator(typename base_type::const_iterator value) const noexcept {
1568 return idictionary < key_t, value_t >::to_const_iterator(value, data_->items, *this);
1569 }
1570
1571 typename base_type::const_iterator to_base_type_iterator(const_iterator value) const noexcept {
1572 return idictionary < key_t, value_t >::to_iterator(value, *this, data_->items);
1573 }
1574
1575 typename base_type::iterator to_base_type_iterator(iterator value) noexcept {
1576 return idictionary < key_t, value_t >::to_iterator(value, *this, data_->items);
1577 }
1578
1579 const_iterator to_type_iterator(typename base_type::const_iterator value) const noexcept {
1580 return idictionary < key_t, value_t >::to_iterator(value, data_->items, *this);
1581 }
1582
1583 iterator to_type_iterator(typename base_type::iterator value) noexcept {
1584 return idictionary < key_t, value_t >::to_iterator(value, data_->items, *this);
1585 }
1586
1587 struct data {
1588 data() : items {size_type {}, hasher {}, equator {}, allocator_type {}} {}
1589 data(ptr < iequality_comparer < key_t>> comparer) : comparer {comparer}, items {size_type {}, hasher {comparer.get()}, equator {comparer.get()}, allocator_type {}} {}
1590 data(size_type bucket_count) noexcept : items {bucket_count, hasher {}, equator {}, allocator_type {}} {}
1591 data(ptr < iequality_comparer < key_t>> comparer, const base_type & items, size_type version) noexcept : comparer {comparer}, items {size_type {}, hasher {comparer.get()}, equator {comparer.get()}, allocator_type {}}, version {version} {
1592 for (const auto& item : items)
1593 this->items.insert(item);
1594 }
1595 data(base_type&& items, size_type version) noexcept : items {size_type {}, hasher {}, equator {}, allocator_type {}}, version {version} {
1596 for (auto&& item : items)
1597 this->items.insert(item);
1598 }
1599
1601 base_type items;
1602 size_type version = 0;
1603 xtd::object sync_root;
1604 };
1606 };
1607
1609 // C++17 deduction guides for xtd::collections::generic::dictionary
1610 // {
1611 template < class key_t, class value_t >
1613
1614 template < class key_t, class value_t >
1616
1617 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 >>>
1618 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 >;
1619
1620 template < class key_t, class value_t, class allocator_t >
1621 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 >;
1622
1623 template < class key_t, class value_t, class allocator_t >
1624 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 >;
1625
1626 template < class key_t, class value_t, class hasher_t, class allocator_t >
1627 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 >;
1628
1629 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 >>>
1630 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 >;
1631
1632 template < class key_t, class value_t, class allocator_t >
1633 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 >;
1634
1635 template < class key_t, class value_t, class allocator_t >
1636 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 >;
1637
1638 template < class key_t, class value_t, class hasher_t, class allocator_t >
1639 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 >;
1640
1641 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 >>>
1642 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 >;
1643
1644 template < class input_iterator_t, class allocator_t >
1645 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 >;
1646
1647 template < class input_iterator_t, class allocator_t >
1648 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 >;
1649
1650 template < class input_iterator_t, class hasher_t, class allocator_t >
1651 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 >;
1652 // }
1654 }
1655 }
1656}
Contains xtd::collections::generic::helpers::allocator alias.
Contains xtd::argument_out_of_range_exception exception.
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:246
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
typename xtd::collections::generic::idictionary< key_t, value_t >::key_type key_type
Represents the dictionary key type.
Definition dictionary.hpp:143
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:1392
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:1309
iterator erase(const_iterator pos)
Erases elements.
Definition dictionary.hpp:950
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:669
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:699
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:1453
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:1361
typename xtd::collections::generic::idictionary< key_type, mapped_type >::value_collection value_collection
Represents the idictionary value collection type.
Definition dictionary.hpp:183
local_iterator end(size_type n)
Returns an iterator to the end of the specified bucket.
Definition dictionary.hpp:885
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:495
const value_t & operator[](const key_t &key) const override
Gets the element with the specified key.
Definition dictionary.hpp:1543
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:549
hasher hash_function() const
Returns function used to hash the keys.
Definition dictionary.hpp:1081
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:1004
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:1115
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:1138
equator key_equal
Represents the dictionary key_equal type.
Definition dictionary.hpp:153
value_type & reference
Represents the dictionary reference type.
Definition dictionary.hpp:161
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:1197
void add(const value_type &item) override
Adds an item to the xtd::collections::generic::icollection <type_t>.
Definition dictionary.hpp:729
node_type extract(const key_t k)
Extracts nodes from the container.
Definition dictionary.hpp:995
size_type capacity() const noexcept
Definition dictionary.hpp:575
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:1091
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:1439
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:588
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:1262
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:1174
const_local_iterator cbegin(size_type n) const
Returns an iterator to the beginning of the specified bucket.
Definition dictionary.hpp:786
value_t & at(const key_t &key)
Gets the element with the specified key.
Definition dictionary.hpp:750
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:1127
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:775
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:845
void reserve(size_type count)
Reserves space for at least the specified number of elements and regenerates the hash table.
Definition dictionary.hpp:1371
void swap(dictionary &other) noexcept
Swaps the contents.
Definition dictionary.hpp:1379
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:900
std::unordered_map< key_type, mapped_type, hasher, key_equal, allocator_type > base_type
Represents the dictionary base type.
Definition dictionary.hpp:159
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:1102
const_iterator find(const find_key_t &x) const
Finds element with specific key.
Definition dictionary.hpp:1021
void clear() noexcept override
Removes all keys and values from the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:800
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:962
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:602
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:1412
const value_t & at(const key_t &key) const
Gets the element with the specified key.
Definition dictionary.hpp:739
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:1353
void merge(dictionary< key_t, value_t, source_hasher_t, source_equator_t, allocator_t > &&source)
Splices nodes from another container.
Definition dictionary.hpp:1289
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:1209
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumerable.
Definition dictionary.hpp:562
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:938
key_value_pair< iterator, bool > emplace(args_t &&...args)
Constructs element in-place.
Definition dictionary.hpp:861
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:1270
iterator emplace_hint(iterator hint, args_t &&...args)
constructs elements in-place using a hint
Definition dictionary.hpp:876
iterator find(const find_key_t &x)
Finds element with specific key.
Definition dictionary.hpp:1029
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:1151
key_value_pair< iterator, iterator > equal_range(const key_t &key)
Returns range of elements matching a specific key.
Definition dictionary.hpp:909
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:1346
void rehash(size_type count)
Reserves at least the specified number of buckets and regenerates the hash table.
Definition dictionary.hpp:1338
const_local_iterator begin(size_type n) const
Returns an iterator to the beginning of the specified bucket.
Definition dictionary.hpp:768
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
typename xtd::collections::generic::idictionary< key_type, mapped_type >::iterator iterator
Represents the iterator of dictionary value type.
Definition dictionary.hpp:169
node_type extract(const_iterator position) noexcept
Extracts nodes from the container.
Definition dictionary.hpp:985
bool contains(const key_t &key) const noexcept
Checks if the container contains element with specific key.
Definition dictionary.hpp:807
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:1403
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:1492
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumerable.
Definition dictionary.hpp:606
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:1163
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:919
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:531
size_type bucket_size(size_type n) const noexcept
Returns the number of elements in the bucket with index n.
Definition dictionary.hpp:780
local_iterator begin(size_type n)
Returns an iterator to the beginning of the specified bucket.
Definition dictionary.hpp:760
iterator end() noexcept override
Returns an iterator to the element following the last element of the enumerable.
Definition dictionary.hpp:610
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:722
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:821
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:929
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:631
size_type size() const noexcept
Gets the number of key/value pairs contained in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:676
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:1466
const_local_iterator end(size_type n) const
Returns an iterator to the end of the specified bucket.
Definition dictionary.hpp:893
value_collection values() const noexcept override
Gets a collection containing the values in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:705
void merge(dictionary< key_t, value_t, source_hasher_t, source_equator_t, allocator_t > &source)
Splices nodes from another container.
Definition dictionary.hpp:1279
std::pair< const key_t, value_t > base_value_type
Represents the dictionary base value type.
Definition dictionary.hpp:157
size_type erase(const key_t &key)
Erases elements.
Definition dictionary.hpp:973
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:1184
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:794
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:1299
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
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:1039
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 contains_key_t &x) const
Checks if the container contains element with specific key.
Definition dictionary.hpp:814
key_collection keys() const noexcept override
Gets a collection containing the keys in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:644
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumerable.
Definition dictionary.hpp:579
virtual const base_type & items() const noexcept
Returns the underlying base type items.
Definition dictionary.hpp:635
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:1319
bool try_get_value(const key_t &key, value_t &value) const override
Gets the value associated with the specified key.
Definition dictionary.hpp:1475
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:1235
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:478
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:831
float load_factor() const
Gets the average number of elements per bucket, that is, xtd::collections::generic::dictionary::size ...
Definition dictionary.hpp:653
typename xtd::collections::generic::idictionary< key_type, mapped_type >::key_collection key_collection
Represents the idictionary key collection type.
Definition dictionary.hpp:181
allocator_t allocator_type
Represents the dictionary allocator type.
Definition dictionary.hpp:155
typename std::allocator_traits< allocator_t >::const_pointer const_pointer
Represents the dictionary const pointer type.
Definition dictionary.hpp:167
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:1329
iterator begin() noexcept override
Returns an iterator to the first element of the enumerable.
Definition dictionary.hpp:565
size_type bucket_count() const noexcept
Definition dictionary.hpp:570
const_iterator cend() const noexcept override
Returns an iterator to the element following the last element of the enumerable.
Definition dictionary.hpp:583
xtd::ptrdiff difference_type
Represents the dictionary difference type.
Definition dictionary.hpp:151
typename std::allocator_traits< allocator_t >::pointer pointer
Represents the dictionary pointer type.
Definition dictionary.hpp:165
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:664
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:1222
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:657
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:1249
typename xtd::collections::generic::idictionary< key_t, value_t >::mapped_type mapped_type
Represents the dictionary mapped type.
Definition dictionary.hpp:145
iterator find(const key_t &key)
Finds element with specific key.
Definition dictionary.hpp:1012
typename xtd::collections::generic::idictionary< key_type, mapped_type >::value_type value_type
Represents the dictionary value type.
Definition dictionary.hpp:147
allocator_type get_allocator() const noexcept
Returns the allocator associated with the container.
Definition dictionary.hpp:1035
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:1386
virtual base_type & items() noexcept
Returns the underlying base type items.
Definition dictionary.hpp:638
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:615
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:1426
float max_load_factor() const
Gets the maximum load factor (number of elements per bucket). The container automatically increases t...
Definition dictionary.hpp:661
xtd::size size_type
Represents the dictionary size type.
Definition dictionary.hpp:149
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:514
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:598
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
virtual const_iterator cbegin() const
Returns an iterator to the first element of the enumerable.
Definition enumerable_iterators.hpp:148
virtual const_iterator begin() const
Returns an iterator to the first element of the enumerable.
Definition enumerable_iterators.hpp:141
virtual const_iterator cend() const
Returns an iterator to the element following the last element of the enumerable.
Definition enumerable_iterators.hpp:152
virtual const_iterator end() const
Returns an iterator to the element following the last element of the enumerable.
Definition enumerable_iterators.hpp:156
Represents a generic collection of key/value pairs.
Definition idictionary.hpp:44
xtd::collections::generic::list< mapped_type > value_collection
Definition idictionary.hpp:62
xtd::collections::generic::list< key_type > key_collection
Definition idictionary.hpp:60
typename xtd::collections::generic::icollection< value_type >::const_iterator const_iterator
Definition idictionary.hpp:58
typename xtd::collections::generic::icollection< value_type >::iterator iterator
Definition idictionary.hpp:56
typename xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< xtd::any_object, xtd::any_object > >::value_type value_type
Definition idictionary.hpp:54
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
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:44
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.
Contains xtd::collections::generic::idictionary <key_t, value_t> interface.
Contains xtd::collections::generic::key_not_found_exception exception.
generic::enumerator< xtd::any_object > enumerator
Supports a simple iteration over a non-generic collection.
Definition enumerator.hpp:28
generic::ienumerable< xtd::any_object > ienumerable
Exposes an enumerator, which supports a simple iteration over a non-generic collection.
Definition ienumerable.hpp:32
generic::idictionary< xtd::any_object, xtd::any_object > idictionary
interface IComparer exposes a method that compares two objects.
Definition idictionary.hpp:27
std::remove_const_t< std::tuple_element_t< 0, iterator_value_t< input_iterator_t > > > iterator_key_t
Represents the key iterator type.
Definition iterator.hpp:44
std::allocator< type_t > allocator
Represent an allocator alias.
Definition allocator.hpp:38
std::tuple_element_t< 1, iterator_value_t< input_iterator_t > > iterator_mapped_t
Represents the mapped iterator type.
Definition iterator.hpp:57
@ argument
The argument is not valid.
Definition exception_case.hpp:31
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
@ invalid_operation
The operation is not valid.
Definition exception_case.hpp:63
@ key_not_found
The key is not found.
Definition exception_case.hpp:69
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
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.
Definition platform_id.hpp:58
@ a
The A key.
Definition console_key.hpp:88
@ add
The Add key.
Definition console_key.hpp:170
@ n
The N key.
Definition console_key.hpp:114
@ k
The K key.
Definition console_key.hpp:108
@ b
The B key.
Definition console_key.hpp:90
@ x
The X key.
Definition console_key.hpp:134
Contains xtd::collections::generic::helpers::hasher struct.
Contains iteraors aliases.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
read_only_span< type_t, count > first() const
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:282
read_only_span< type_t, count > last() const
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:307
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201
Contains xtd::new_ptr method.
Contains xtd::ptr type.
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
Implements a function object for performing comparisons. Unless specialised, invokes operator== on ty...
Definition equator.hpp:38
Implements a function object for hashing data.
Definition hasher.hpp:39