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"
11#include "../../argument_out_of_range_exception.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 }
95
96 private:
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 }
130
131 private:
132 friend class dictionary;
133 equator() = default;
135 const iequality_comparer<key_t>* comparer = nullptr;
136 };
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 }
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 }
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 }
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 }
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 }
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)
464 add(key, value);
465 }
476 dictionary(std::initializer_list<base_value_type> init, size_type bucket_count, const allocator_type& alloc) : data_(xtd::new_ptr<data>(bucket_count)) {
477 for (const auto& [key, value] : init)
478 add(key, value);
479 }
491 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)) {
492 for (const auto& [key, value] : init)
493 add(key, value);
494 }
507 template <class init_key_t, class init_value_t>
508 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)) {
509 for (const auto& [key, value] : init)
510 add(key, value);
511 }
522 template <class init_key_t, class init_value_t>
524 for (const auto& [key, value] : init)
525 add(key, value);
526 }
538 template <class init_key_t, class init_value_t>
539 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)) {
540 for (const auto& [key, value] : init)
541 add(key, value);
542 }
544
546
550 const_iterator begin() const noexcept override {return ienumerable<value_type>::begin();}
553 iterator begin() noexcept override {return ienumerable<value_type>::begin();}
554
558 size_type bucket_count() const noexcept {return data_->items.bucket_count();}
559
563 size_type capacity() const noexcept {return bucket_count();}
564
567 const_iterator cbegin() const noexcept override {return ienumerable<value_type>::cbegin();}
568
571 const_iterator cend() const noexcept override {return ienumerable<value_type>::cend();}
572
576 const iequality_comparer<key_t>& comparer() const noexcept {
577 if (data_->comparer) return *data_->comparer;
579 }
580
586 size_type count() const noexcept override {return data_->items.size();}
587
590 bool empty() const noexcept {return data_->items.empty();}
591
594 const_iterator end() const noexcept override {return ienumerable<value_type>::cend();}
595
598 iterator end() noexcept override {return ienumerable<value_type>::cend();}
599
603 bool is_read_only() const noexcept override {return false;}
604
619 bool is_synchronized() const noexcept override {return false;}
620
623 virtual const base_type& items() const noexcept {return data_->items;}
626 virtual base_type& items() noexcept {return data_->items;}
627
632 key_collection keys() const noexcept override {
633 auto keys = key_collection {};
634 for (const auto& [key, value] : data_->items)
635 keys.add(key);
636 return keys;
637 }
638
641 float load_factor() const {return data_->items.load_factor();}
642
645 size_type max_bucket_count() const noexcept {return data_->items.max_bucket_count();}
646
649 float max_load_factor() const {return data_->items.max_load_factor();}
652 void max_load_factor(float value) const {data_->items.max_load_factor(value);}
653
657 size_type max_size() const noexcept {return data_->items.max_size();}
658
664 size_type size() const noexcept {return data_->items.size();}
665
687 const xtd::object& sync_root() const noexcept override {return data_->sync_root;}
688
693 value_collection values() const noexcept override {
694 auto values = value_collection {};
695 for (const auto& [key, value] : data_->items)
696 values.add(value);
697 return values;
698 }
700
702
710 void add(const key_t& key, const value_t value) override {
712 }
713
717 void add(const value_type& item) override {
718 add(item.key(), item.value());
719 }
720
721
727 const value_t& at(const key_t& key) const {
728 auto iterator = data_->items.find(key);
730 return iterator->second;
731 }
732
738 value_t& at(const key_t& key) {
739 auto iterator = data_->items.find(key);
741 return iterator->second;
742 }
743
749 return data_->items.begin(n);
750 }
751
757 return data_->items.begin(n);
758 }
759
763 size_type bucket(const key_t& key) const {return data_->items.bucket(key);}
764
768 size_type bucket_size(size_type n) const noexcept {return data_->items.bucket_size(n);}
769
775 return data_->items.begin(n);
776 }
777
783 return data_->items.end(n);
784 }
785
788 void clear() noexcept override {
789 data_->items.clear();
790 ++data_->version;
791 }
792
795 bool contains(const key_t& key) const noexcept {
796 return data_->items.find(key) != data_->items.end();
797 }
798
801 template <class contains_key_t>
802 bool contains(const contains_key_t& x) const {
803 return data_->items.find(x) != data_->items.end();
804 }
805
809 bool contains(const value_type& item) const noexcept override {
810 auto iterator = find(item.key());
811 if (iterator == end()) return false;
812 return iterator->value() == item.value();
813 }
814
819 bool contains_key(const key_t& key) const noexcept override {
820 return contains(key);
821 }
822
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;
826 return false;
827 }
828
833 void copy_to(xtd::array<value_type>& array, xtd::size array_index) const override {
835 auto index = size_type {0};
836 for (const auto& item : *this)
837 array[array_index + index++] = item;
838 }
839
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};
853 }
854
863 template <class ...args_t>
864 iterator emplace_hint(iterator hint, args_t&& ...args) {
865 ++data_->version;
866 return to_type_iterator(data_->items.emplace_hint(to_base_type_iterator(hint), std::forward<args_t>(args)...));
867 }
868
874 return data_->items.end(n);
875 }
876
882 return data_->items.end(n);
883 }
884
889 data_->items.reserve(capacity);
890 return this->capacity();
891 }
892
898 const auto& [first, last] = data_->items.equal_range(key);
899 return {to_type_iterator(first), to_type_iterator(last)};
900 }
901
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)};
910 }
911
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)};
920 }
921
927 const auto& [first, last] = data_->items.equal_range(x);
928 return {to_type_iterator(first), to_type_iterator(last)};
929 }
930
939 ++data_->version;
940 return to_type_iterator(data_->items.erase(to_base_type_iterator(pos)));
941 }
951 ++data_->version;
952 return to_type_iterator(data_->items.erase(to_base_type_iterator(first), to_base_type_iterator(last)));
953 }
961 size_type erase(const key_t& key) {
962 auto removed_count = data_->items.erase(key);
963 if (removed_count) ++data_->version;
964 return removed_count;
965 }
966
973 node_type extract(const_iterator position) noexcept {
974 ++data_->version;
975 return data_->items.extract(to_base_type_iterator(position));
976 }
983 node_type extract(const key_t k) {
984 ++data_->version;
985 return data_->items.extract(k);
986 }
987
992 const_iterator find(const key_t& key) const {
993 return to_type_iterator(data_->items.find(key));
994 }
995
1000 const_iterator find(const key_t& key) {
1001 return to_type_iterator(data_->items.find(key));
1002 }
1003
1008 template <class find_key_t>
1009 const_iterator find(const find_key_t& x) const {
1010 return to_type_iterator(data_->items.find(x));
1011 }
1012
1016 template <class find_key_t>
1017 iterator find(const find_key_t& x) {
1018 return to_type_iterator(data_->items.find(x));
1019 }
1020
1023 allocator_type get_allocator() const noexcept {return data_->items.get_allocator();}
1024
1027 enumerator<value_type> get_enumerator() const noexcept override {
1028 struct internal_enumerator : public ienumerator<value_type> {
1029 public:
1030 explicit internal_enumerator(const dictionary& items, size_type version) : items_(items), version_(version) {}
1031
1032 const value_type& current() const override {
1033 if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
1034 if (iterator_ != items_.items().cend()) {
1035 static thread_local auto value = value_type {};
1036 value = value_type {*iterator_};
1037 return value;
1038 }
1039 static auto default_value_type = value_type {};
1040 return default_value_type;
1041 }
1042
1043 bool move_next() override {
1044 if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
1045 if (!reset_) return ++iterator_ != items_.items().cend();
1046 reset_ = false;
1047 iterator_ = items_.items().cbegin();
1048 return iterator_ != items_.items().cend();
1049 }
1050
1051 void reset() override {
1052 reset_ = true;
1053 version_ = items_.data_->version;
1054 iterator_ = items_.items().cend();
1055 }
1056
1057 protected:
1058 bool reset_ = true;
1059 const dictionary& items_;
1060 typename dictionary::base_type::const_iterator iterator_ = items_.items().cend();
1061 size_type version_ = 0;
1062 };
1063 return {new_ptr<internal_enumerator>(*this, data_->version)};
1064 }
1065
1070 return data_->items.hash_function();
1071 }
1072
1080 const auto& [iterator, succeeded] = data_->items.insert(value);
1081 if (succeeded) ++data_->version;
1082 return {to_type_iterator(iterator), succeeded};
1083 }
1091 const auto& [iterator, succeeded] = data_->items.insert(value);
1092 if (succeeded) ++data_->version;
1093 return {to_type_iterator(iterator), succeeded};
1094 }
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};
1107 }
1116 ++data_->version;
1117 return to_type_iterator(data_->items.insert(to_base_type_iterator(hint), value));
1118 }
1127 ++data_->version;
1128 return to_type_iterator(data_->items.insert(to_base_type_iterator(hint), value));
1129 }
1138 template <class type_t>
1139 iterator insert(const_iterator hint, type_t&& value) {
1140 ++data_->version;
1141 return to_type_iterator(data_->items.insert(to_base_type_iterator(hint), value));
1142 }
1150 template <class input_iterator_t>
1151 void insert(input_iterator_t first, input_iterator_t last) {
1152 for (auto iterator = first; iterator != last; ++iterator) {
1153 const auto& [key, value] = *iterator;
1154 add(key, value);
1155 }
1156 }
1162 void insert(std::initializer_list<base_value_type> ilist) {
1163 for (const auto& [key, value] : ilist)
1164 add(std::forward<value_type>({key, value}));
1165 }
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}));
1175 }
1186 ++data_->version;
1187 return data_->items.inser(nh);
1188 }
1198 ++data_->version;
1199 return to_type_iterator(data_->items.inser(to_base_type_iterator(hint), nh));
1200 }
1201
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};
1214 }
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};
1227 }
1236 template <class type_t>
1237 iterator insert_or_assign(const_iterator hint, const key_t& k, type_t&& obj) {
1238 ++data_->version;
1239 return to_type_iterator(data_->items.insert_or_assign(to_base_type_iterator(hint), k, obj));
1240 }
1249 template <class type_t>
1250 iterator insert_or_assign(const_iterator hint, key_t&& k, type_t&& obj) {
1251 ++data_->version;
1252 return to_type_iterator(data_->items.insert_or_assign(to_base_type_iterator(hint), std::move(k), obj));
1253 }
1254
1259 return data_->items.key_eq();
1260 }
1261
1266 template <class source_hasher_t, class source_equator_t>
1268 data_->items.merge(source.items);
1269 ++data_->version;
1270 }
1271
1276 template <class source_hasher_t, class source_equator_t>
1278 data_->items.merge(std::move(source.items));
1279 ++data_->version;
1280 }
1281
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);
1289 ++data_->version;
1290 }
1291
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));
1299 ++data_->version;
1300 }
1301
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);
1309 ++data_->version;
1310 }
1311
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));
1319 ++data_->version;
1320 }
1321
1327 data_->items.rehash(count);
1328 }
1329
1334 bool remove(const key_t& key) noexcept override {
1335 return erase(key) == 1;
1336 }
1337
1341 bool remove(const value_type& item) noexcept override {
1342 if (!contains_value(item.value())) return false;
1343 return erase(item.key()) == 1;
1344 }
1345
1349 bool remove(const key_t& key, value_t& value) noexcept {
1350 auto iterator = find(key);
1351 if (iterator == end()) return false;
1352 value = iterator->value();
1353 return erase(iterator) != end();
1354 }
1355
1360 data_->items.reserve(count);
1361 }
1362
1367 void swap(dictionary& other) noexcept {
1368 data_->items.swap(other.data_->items);
1369 std::swap(data_->version, other.data_->version);
1370 }
1371
1374 xtd::string to_string() const noexcept override {return xtd::string::format("{{{}}}", xtd::string::join(", ", *this));}
1375
1383 }
1384
1392 rehash(count());
1393 }
1394
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;
1403 return succeeded;
1404 }
1405
1413 template <class ...args_t>
1414 key_value_pair<iterator, bool> try_emplace(const key_t& k, args_t&&... args) {
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};
1418 }
1426 template <class ...args_t>
1427 key_value_pair<iterator, bool> try_emplace(key_t&& k, args_t&&... args) {
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};
1431 }
1440 template <class ...args_t>
1441 iterator try_emplace(const_iterator hint, const key_t& k, args_t&&... args) {
1442 ++data_->version;
1443 return to_type_iterator(data_->items.try_emplace(to_base_type_iterator(hint), k, std::forward<args_t>(args)...));
1444 }
1453 template <class ...args_t>
1454 iterator try_emplace(const_iterator hint, key_t&& k, args_t&&... args) {
1455 ++data_->version;
1456 return to_type_iterator(data_->items.try_emplace(to_base_type_iterator(hint), std::move(k), std::forward<args_t>(args)...));
1457 }
1458
1463 bool try_get_value(const key_t& key, value_t& value) const override {
1464 auto iterator = find(key);
1465 if (iterator != end()) {
1466 value = iterator->value();
1467 return true;
1468 }
1469 value = value_t {};
1470 return false;
1471 }
1473
1475
1481 data_->comparer = std::move(other.data_->comparer);
1482 data_->items = std::move(other.data_->items);
1483 data_->version = std::move(other.data_->version);
1484 return *this;
1485 }
1489 dictionary& operator =(std::unordered_map<key_t, value_t>&& other) noexcept {
1490 data_->items = std::move(other);
1491 ++data_->version;
1492 return *this;
1493 }
1497 dictionary& operator =(const dictionary& other) noexcept = default;
1501 dictionary& operator =(const std::unordered_map<key_t, value_t>& other) noexcept {
1502 data_->items.clear();
1503 for (const auto& [key, value] : other)
1504 add(key, value);
1505 }
1509 dictionary& operator =(std::initializer_list<base_value_type> ilist) {
1510 data_->items.clear();
1511 for (const auto& [key, value] : ilist)
1512 add(key, value);
1513 }
1517 template <class init_key_t, class init_value_t>
1519 data_->items.clear();
1520 for (const auto& [key, value] : ilist)
1521 add(key, value);
1522 }
1523
1531 const value_t& operator [](const key_t& key) const override {return at(key);}
1538 value_t& operator [](const key_t& key) override {
1539 ++data_->version;
1540 return data_->items[key];}
1541
1544 operator const base_type&() const noexcept {return data_->items;}
1547 operator base_type&() noexcept {return data_->items;}
1549
1550 private:
1551 typename base_type::const_iterator to_base_type_iterator(const_iterator value) const noexcept {
1552 return idictionary<key_t, value_t>::to_iterator(value, *this, data_->items);
1553 }
1554
1555 typename base_type::iterator to_base_type_iterator(iterator value) noexcept {
1556 return idictionary<key_t, value_t>::to_iterator(value, *this, data_->items);
1557 }
1558
1559 const_iterator to_type_iterator(typename base_type::const_iterator value) const noexcept {
1560 return idictionary<key_t, value_t>::to_iterator(value, data_->items, *this);
1561 }
1562
1563 iterator to_type_iterator(typename base_type::iterator value) noexcept {
1564 return idictionary<key_t, value_t>::to_iterator(value, data_->items, *this);
1565 }
1566
1567 struct data {
1568 data() : items {size_type {}, hasher {}, equator {}, allocator_type {}} {}
1569 data(ptr<iequality_comparer<key_t>> comparer) : comparer {comparer}, items {size_type {}, hasher {comparer.get()}, equator {comparer.get()}, allocator_type {}} {}
1570 data(size_type bucket_count) noexcept : items {bucket_count, hasher {}, equator {}, allocator_type {}} {}
1571 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} {
1572 for (const auto& item : items)
1573 this->items.insert(item);
1574 }
1575 data(base_type&& items, size_type version) noexcept : items {size_type {}, hasher {}, equator {}, allocator_type {}}, version {version} {
1576 for (auto&& item : items)
1577 this->items.insert(item);
1578 }
1579
1580 ptr<iequality_comparer<key_t>> comparer;
1581 base_type items;
1582 size_type version = 0;
1583 xtd::object sync_root;
1584 };
1585 xtd::ptr<data> data_ = xtd::new_ptr<data>();
1586 };
1587
1589 // C++17 deduction guides for xtd::collections::generic::dictionary
1590 // {
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>>>;
1593
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>>>;
1596
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>;
1599
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>;
1602
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>;
1605
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>;
1608
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>;
1611
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>;
1614
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>;
1617
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>;
1620
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>;
1623
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>;
1626
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>;
1629
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>;
1632 // }
1634 }
1635 }
1636}
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
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
@ 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.
@ a
The A key.
@ add
The Add key.
@ n
The N key.
@ k
The K key.
@ b
The B key.
@ x
The X key.
@ 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