5#define __XTD_CORE_INTERNAL__
7#undef __XTD_CORE_INTERNAL__
62 template<
typename key_t,
typename value_t,
typename hasher_t,
typename equator_t,
typename allocator_t>
79 using base_type = std::unordered_map < key_type, mapped_type, hasher_t, equator_t, allocator_t >;
143 for (
const auto& item : collection)
149 for (
const auto& [key, value] :
items)
202 for (
const auto& item : collection)
217 data_->items.reserve(
other.size());
218 for (
auto&& item :
other) {
219 data_->items.insert(std::move(item));
227 dictionary(
const std::unordered_map < key_t, value_t >& other) {
228 for (
const auto& [key, value] :
other)
239 for (
const auto& [key, value] : init)
250 template <
class init_key_t,
typename init_value_t >
251 explicit dictionary(std::initializer_list < key_value_pair < init_key_t, init_value_t>> init) {
252 for (
const auto& [key, value] : init)
261 template <
class input_iterator_t >
264 const auto& [key, value] = *
iterator;
283 return *data_->comparer;
291 [[nodiscard]]
auto count() const noexcept ->
size_type override {
return data_->items.size();}
295 [[nodiscard]]
virtual auto items() const noexcept -> const
base_type& {
return data_->items;}
306 for (
const auto& [key, value] : data_->items)
317 for (
const auto& [key, value] : data_->items)
332 auto add(
const key_t & key,
const value_t& value) ->
void override {
340 add(item.key(), item.value());
345 auto clear() noexcept ->
void override {
346 data_->items.clear();
356 return iterator->second == item.value();
363 [[nodiscard]]
auto contains_key(
const key_t & key)
const noexcept ->
bool override {
364 return data_->items.find(key) != data_->items.end();
372 for (
const auto& [item_key, item_value] :
self_)
373 if (item_value == value)
return true;
383 for (
const auto& item :
self_)
384 array[array_index++] = item;
392 return self_.capacity();
398 struct dictionary_enumerator :
public ienumerator < value_type > {
401 [[nodiscard]]
const value_type& current()
const override {
407 [[nodiscard]]
bool move_next()
override {
409 if (index_++ && iterator_ != items_.data_->items.cend()) ++iterator_;
410 else iterator_ = items_.items().cbegin();
411 return iterator_ != items_.data_->items.cend();
414 void reset()
override {
416 version_ = items_.data_->version;
417 iterator_ = items_.items().cend();
423 typename dictionary::base_type::const_iterator iterator_ = items_.data_->items.cend();
434 auto remove(
const key_t & key)
noexcept ->
bool override {
435 return items().erase(key) == 1;
443 return items().erase(item.key()) == 1;
449 auto remove(
const key_t & key, value_t& value)
noexcept ->
bool {
484 [[nodiscard]]
auto try_add(
const key_t & key,
const value_t value)
noexcept ->
bool {
485 const auto& [
iterator, succeeded] = data_->items.insert(std::forward < base_value_type > ({key, value}));
486 if (succeeded) ++data_->version;
494 [[nodiscard]]
auto try_get_value(
const key_t & key, value_t& value)
const ->
bool override {
512 data_->comparer = std::move(
other.data_->comparer);
513 data_->items = std::move(
other.data_->items);
514 data_->version = std::move(
other.data_->version);
521 data_->items = std::move(
other);
533 data_->items.clear();
534 for (
const auto& [key, value] :
other)
541 data_->items.clear();
542 for (
const auto& [key, value] :
ilist)
548 template <
class init_key_t,
typename init_value_t >
550 data_->items.clear();
551 for (
const auto& [key, value] :
ilist)
562 [[nodiscard]]
const value_t&
operator [](
const key_t & key)
const override {
563 auto iterator = data_->items.find(key);
575 return data_->items[key];
580 operator const base_type& ()
const noexcept {
return data_->items;}
586 operator std::unordered_map<key_t, value_t>() const noexcept {
587 std::unordered_map<key_t, value_t> result;
588 for (
auto& [key, value] : data_->items)
595 auto is_read_only() const noexcept ->
bool override {
return false;}
599 struct dictionary_data {
600 dictionary_data() =
default;
602 dictionary_data(
const xtd::collections::generic::iequality_comparer<key_type>& comparer,
const base_type & items,
size_type version) noexcept : comparer {&comparer}, items {
size_type {}, hasher_t {comparer}, equator_t {comparer}}, version {version} {
603 for (
const auto& item : items)
604 self_.items.insert(item);
607 for (
auto&& item : items)
608 self_.items.insert(item);
611 const xtd::collections::generic::iequality_comparer<key_type>* comparer =
null;
614 xtd::object sync_root;
622 template<
typename key_t,
typename value_t >
625 template<
typename key_t,
typename value_t >
628 template<xtd::iterable iterable_t>
631 template<
typename key_t,
typename value_t >
634 template<
typename key_t,
typename value_t >
637 template<
typename input_iterator_t >
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
virtual auto length() const noexcept -> size_type
Gets a size that represents the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:122
static auto join(const basic_string &separator, const collection_t &values) noexcept -> basic_string
Definition basic_string.hpp:1241
Represents a collection of keys and values.
Definition dictionary.hpp:63
typename xtd::collections::generic::idictionary< xtd::intptr, xtd::ptr< collection_type > >::key_type key_type
Definition dictionary.hpp:69
auto try_get_value(const key_t &key, value_t &value) const -> bool override
Gets the value associated with the specified key.
Definition dictionary.hpp:494
dictionary(const xtd::collections::generic::ienumerable< value_type > &collection)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that c...
Definition dictionary.hpp:142
dictionary(dictionary &&other) noexcept=default
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
dictionary(const dictionary &other)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:212
typename xtd::collections::generic::idictionary< key_type, mapped_type >::value_collection value_collection
Definition dictionary.hpp:83
const value_t & operator[](const key_t &key) const override
Gets the element with the specified key.
Definition dictionary.hpp:562
auto values() const noexcept -> value_collection override
Gets a collection containing the values in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:315
auto remove(const value_type &item) noexcept -> bool override
Removes the first occurrence of a specific object from the xtd::collections::generic::dictionary <key...
Definition dictionary.hpp:441
auto trim_excess() -> void
Sets the capacity of this dictionary to what it would be if it had been originally initialized with a...
Definition dictionary.hpp:475
auto to_string() const noexcept -> xtd::string override
Gets a string that represents the current object.
Definition dictionary.hpp:458
auto contains_value(const value_t &value) const noexcept -> bool
Determines whether the xtd::collections::generic::dictionary <key_t, value_t> contains the specified ...
Definition dictionary.hpp:371
dictionary(const xtd::collections::generic::ienumerable< value_type > &collection, const xtd::collections::generic::iequality_comparer< key_type > &comparer)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that c...
Definition dictionary.hpp:201
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:227
equator_t equator
Definition dictionary.hpp:85
auto comparer() const noexcept -> const xtd::collections::generic::iequality_comparer< xtd::intptr > &
Definition dictionary.hpp:281
dictionary(xtd::iterable auto &&items)
Initializes a new instance of the xtd::iterable that contains elements copied from the specified coll...
Definition dictionary.hpp:148
dictionary(std::initializer_list< base_value_type > init)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:238
dictionary(input_iterator_t first, input_iterator_t last)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:262
dictionary() noexcept=default
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that i...
virtual auto items() const noexcept -> const base_type &
Definition dictionary.hpp:295
hasher_t hasher
Definition dictionary.hpp:87
auto contains(const value_type &item) const noexcept -> bool override
Determines whether an element is in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:353
xtd::usize size_type
Definition dictionary.hpp:75
dictionary(xtd::usize capacity, const xtd::collections::generic::iequality_comparer< key_type > &comparer)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that i...
Definition dictionary.hpp:179
std::unordered_map< key_type, mapped_type, hasher_t, equator_t, allocator_t > base_type
Definition dictionary.hpp:79
auto capacity() const noexcept -> size_type
Definition dictionary.hpp:276
auto operator=(dictionary &&other) noexcept -> dictionary &
Move assignment operator. Replaces the contents with a copy of the contents of other.
Definition dictionary.hpp:511
auto keys() const noexcept -> key_collection override
Gets a collection containing the keys in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:304
auto trim_excess(size_type capacity) -> void
Sets the capacity of this dictionary to hold up a specified number of entries without any further exp...
Definition dictionary.hpp:464
auto try_add(const xtd::intptr &key, const xtd::ptr< collection_type > value) noexcept -> bool
Definition dictionary.hpp:484
auto contains_key(const key_t &key) const noexcept -> bool override
Determines whether the xtd::collections::generic::dictionary <key_t, value_t> contains the specified ...
Definition dictionary.hpp:363
std::pair< const xtd::intptr, xtd::ptr< collection_type > > base_value_type
Definition dictionary.hpp:77
virtual auto items() noexcept -> base_type &
Returns the underlying base type items.
Definition dictionary.hpp:298
auto add(const value_type &item) -> void override
Adds an item to the xtd::collections::generic::icollection <type_t>.
Definition dictionary.hpp:339
auto add(const xtd::intptr &key, const xtd::ptr< collection_type > &value) -> void override
Definition dictionary.hpp:332
dictionary(std::initializer_list< key_value_pair< init_key_t, init_value_t > > init)
Initializes instance of the xtd::collections::generic::dictionary <key_t, value_t> class from a varie...
Definition dictionary.hpp:251
dictionary(const xtd::collections::generic::idictionary< key_t, value_t > &dictionary, const xtd::collections::generic::iequality_comparer< key_type > &comparer)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that c...
Definition dictionary.hpp:192
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:397
auto count() const noexcept -> size_type override
Gets the number of key/value pairs contained in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:291
auto copy_to(xtd::array< value_type > &array, xtd::usize array_index) const -> void override
Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array,...
Definition dictionary.hpp:381
auto remove(const key_t &key) noexcept -> bool override
Removes the value with the specified key from the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:434
auto remove(const key_t &key, value_t &value) noexcept -> bool
Removes the value with the specified key from the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:449
typename xtd::collections::generic::idictionary< key_type, mapped_type >::key_collection key_collection
Definition dictionary.hpp:81
auto clear() noexcept -> void override
Removes all keys and values from the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:345
typename xtd::collections::generic::idictionary< xtd::intptr, xtd::ptr< collection_type > >::mapped_type mapped_type
Definition dictionary.hpp:71
typename xtd::collections::generic::idictionary< key_type, mapped_type >::value_type value_type
Definition dictionary.hpp:73
dictionary(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:216
auto ensure_capacity(xtd::usize capacity) noexcept -> size_type
Definition dictionary.hpp:390
dictionary(xtd::usize capacity)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that i...
Definition dictionary.hpp:166
dictionary(const xtd::collections::generic::iequality_comparer< key_type > &comparer)
Initializes a new instance of the xtd::collections::generic::dictionary <key_t, value_t> class that i...
Definition dictionary.hpp:157
static auto default_equality_comparer() -> const equality_comparer &
Gets the default equality comparer for the type specified by the generic argument.
Definition equality_comparer.hpp:42
auto end() const -> const_iterator
Definition enumerable_iterators.hpp:166
auto last() const -> xtd::collections::generic::key_value_pair< xtd::intptr, xtd::ptr< collection_type > >
Definition enumerable.hpp:337
auto first() const -> xtd::collections::generic::key_value_pair< xtd::intptr, xtd::ptr< collection_type > >
Definition enumerable.hpp:293
Represents a generic collection of key/value pairs.
Definition idictionary.hpp:47
xtd::collections::generic::list< mapped_type > value_collection
Definition idictionary.hpp:65
xtd::collections::generic::list< key_type > key_collection
Definition idictionary.hpp:63
virtual auto sync_root() const noexcept -> const xtd::object &=0
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
virtual auto count() const noexcept -> xtd::usize=0
Gets the number of elements contained in the xtd::collections::generic::icollection <type_t>.
xtd::any_object key_type
Definition idictionary.hpp:53
typename xtd::collections::generic::icollection< value_type >::iterator iterator
Definition idictionary.hpp:59
virtual auto is_read_only() const noexcept -> bool=0
Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
xtd::any_object mapped_type
Definition idictionary.hpp:55
virtual auto is_synchronized() const noexcept -> bool=0
Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is sync...
typename xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< xtd::any_object, xtd::any_object > >::value_type value_type
Definition idictionary.hpp:57
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:46
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:42
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
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:40
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:115
Definition iterable.hpp:15
xtd::collections::generic::comparer< xtd::any_object > comparer
Exposes a method that compares two objects.
Definition comparer.hpp:25
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:65
@ key_not_found
The key is not found.
Definition exception_case.hpp:71
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
null_ptr null
Represents a null pointer value.
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
auto new_ptr(args_t &&... args) -> xtd::ptr< type_t >
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:60
Contains xtd::collections::generic::list <type_t> class.
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
Contains xtd::new_ptr method.
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:39
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37