32 template<
class key_t,
class value_t,
class allocator_t = xtd::collections::
generic::helpers::allocator<std::pair<const key_t, value_t>>>
88 data_->keys.add(item.first);
102 data_->keys.add(item.first);
108 for (
const auto& item : collection)
117 for (
const auto& item : collection)
129 data_->keys.capacity(capacity);
130 data_->items.ensure_capacity(capacity);
143 data_->keys.capacity(capacity);
162 template <
class input_iterator_t >
176 for (
const auto& [key, value] : init)
186 template <
class init_key_t,
class init_value_t >
188 for (
const auto& [key, value] : init)
207 return data_->items.comparer();
223 for (
const auto& key : data_->keys)
234 for (
const auto& key : data_->keys)
235 values.add(data_->items[key]);
249 auto add(
const key_t & key,
const value_t& value) ->
void override {
262 auto clear() noexcept ->
void override {
263 lock_(data_->sync_op) {
265 data_->items.clear();
274 return data_->items.contains(item);
282 return data_->items.contains_key(key);
290 return data_->items.contains_value(value);
299 for (
const auto& item :
self_)
300 array[array_index++] = item;
306 struct ordered_dictionary_enumerator :
public ienumerator<value_type> {
312 return (value_ =
value_type {key_t {items_.data_->keys[index_]}, value_t {items_.data_->items[items_.data_->keys[index_]]}});
315 bool move_next()
override {
317 return ++index_ < items_.data_->keys.count();
320 void reset()
override {
321 version_ = items_.data_->version;
350 lock_(data_->sync_op) {
351 data_->items.add(key, value);
352 data_->keys.insert(index, key);
361 auto remove(
const key_t & key)
noexcept ->
bool override {
363 lock_(data_->sync_op) {
374 lock_(data_->sync_op) {
375 auto result = data_->items.remove(item.first);
376 if (!result)
return false;
377 data_->keys.remove_at(get_index(item.first));
389 lock_(data_->sync_op) {
390 data_->items.remove(data_->keys[index]);
391 data_->keys.remove_at(index);
398 auto to_string() const noexcept ->
xtd::
string override {
return xtd::string::format(
"{{{}}}", xtd::string::join(
", ",
self_));}
404 auto try_get_value(
const key_t & key, value_t& value)
const ->
bool override {
405 return data_->items.try_get_value(key, value);
420 *data_ = *
other.data_;
428 for (
const auto& [key, value] : ilist)
435 template <
class init_key_t,
class init_value_t >
438 for (
const auto& [key, value] : ilist)
467 const value_t&
operator [](
const key_t & key)
const override {
return data_->items[key];}
475 auto iterator = data_->items.items().find(key);
476 if (
iterator != data_->items.items().end())
478 data_->keys.add(key);
479 return data_->items[key];
484 operator const base_type& ()
const noexcept {
return data_->items;}
491 auto get_index(
const key_t & key)
const noexcept ->
xtd::size {
493 for (
const auto& item_key : data_->keys) {
494 if (item_key == key)
return index;
500 auto is_read_only() const noexcept ->
bool override {
return false;}
501 auto is_synchronized() const noexcept ->
bool override {
return false;}
502 const xtd::object& sync_root() const noexcept
override {
return data_->sync_root;}
504 struct dictionary_data {
505 dictionary_data() noexcept = default;
506 dictionary_data(const
base_type & items,
size_type version) noexcept : items {items}, version {version} {
507 for (
const auto& item : this->items)
508 keys.add(item.first);
510 dictionary_data(
base_type&& items,
size_type version) noexcept : items {items}, version {version} {
511 for (
const auto& item : this->items)
512 keys.add(item.first);
518 xtd::object sync_root;
527 template <
class key_t,
class value_t >
528 ordered_dictionary(xtd::collections::generic::idictionary < key_t, value_t >) -> ordered_dictionary < key_t, value_t>;
530 template <
class key_t,
class value_t >
533 template <
class key_t,
class value_t >
534 ordered_dictionary(std::initializer_list < key_value_pair < key_t, value_t>>) -> ordered_dictionary < key_t, value_t >;
536 template <
class key_t,
class value_t >
537 ordered_dictionary(std::initializer_list < std::pair < key_t, value_t>>) -> ordered_dictionary < key_t, value_t >;
539 template <
class input_iterator_t >
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Represents a collection of keys and values.
Definition dictionary.hpp:67
auto keys() const noexcept -> key_collection override
Gets a collection containing the keys in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:302
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:289
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
xtd::any_object key_type
Definition idictionary.hpp:50
typename xtd::collections::generic::icollection< value_type >::iterator iterator
Definition idictionary.hpp:56
xtd::any_object mapped_type
Definition idictionary.hpp:52
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
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 strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
Represents a collection of key/value pairs that are accessible by the key or index.
Definition ordered_dictionary.hpp:33
auto clear() noexcept -> void override
Removes all keys and values from the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:262
const value_t & operator[](const key_t &key) const override
Gets the element with the specified key.
Definition ordered_dictionary.hpp:467
auto add(const key_t &key, const value_t &value) -> void override
Adds an element with the provided key and value to the xtd::collections::generic::ordered_dictionary ...
Definition ordered_dictionary.hpp:249
xtd::collections::generic::enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:305
auto to_string() const noexcept -> xtd::string override
Gets a string that represents the current object.
Definition ordered_dictionary.hpp:398
auto insert(xtd::size index, const key_t &key) -> void
Inserts a new entry into the xtd::collections::generic::ordered_dictionary collection with the specif...
Definition ordered_dictionary.hpp:340
auto operator()(xtd::size index) -> value_t &
Sets the value at the specified index.
Definition ordered_dictionary.hpp:458
xtd::size size_type
Represents the dictionary size type.
Definition ordered_dictionary.hpp:45
xtd::collections::generic::dictionary< key_type, mapped_type > base_type
Represents the dictionary base type.
Definition ordered_dictionary.hpp:49
typename xtd::collections::generic::idictionary< key_type, mapped_type >::value_collection value_collection
Represents the idictionary value collection type.
Definition ordered_dictionary.hpp:55
auto contains(const value_type &item) const noexcept -> bool override
Determines whether an element is in the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:273
auto remove_at(xtd::size index) -> void
Removes the entry at the specified index from the OrderedDictionary collection.
Definition ordered_dictionary.hpp:388
auto count() const noexcept -> size_type override
Gets the number of key/value pairs contained in the xtd::collections::generic::ordered_dictionary <ke...
Definition ordered_dictionary.hpp:201
auto contains_value(const value_t &value) const noexcept -> bool
Determines whether the xtd::collections::generic::ordered_dictionary <key_t, value_t> contains the sp...
Definition ordered_dictionary.hpp:289
auto remove(const value_type &item) noexcept -> bool override
Removes the first occurrence of a specific object from the xtd::collections::generic::ordered_diction...
Definition ordered_dictionary.hpp:373
ordered_dictionary(const xtd::collections::generic::ienumerable< value_type > &collection)
Initializes a new instance of the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:107
auto operator()(xtd::size index) const -> const value_t &
Gets the value at the specified index.
Definition ordered_dictionary.hpp:450
ordered_dictionary(const ordered_dictionary &other) noexcept
Initializes instance of the xtd::collections::generic::ordered_dictionary <key_t, value_t> class from...
Definition ordered_dictionary.hpp:170
xtd::collections::generic::list< key_type > list_type
Represents the dictionary base type.
Definition ordered_dictionary.hpp:51
ordered_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::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:98
auto operator=(ordered_dictionary &&other) noexcept -> ordered_dictionary &=default
Move assignment operator. Replaces the contents with a copy of the contents of other.
typename xtd::collections::generic::idictionary< key_type, mapped_type >::value_type value_type
Represents the dictionary value type.
Definition ordered_dictionary.hpp:43
auto add(const value_type &item) -> void override
Adds an item to the xtd::collections::generic::icollection <type_t>.
Definition ordered_dictionary.hpp:256
virtual auto items() noexcept -> base_type &
Returns the underlying base type items.
Definition ordered_dictionary.hpp:215
auto values() const noexcept -> value_collection override
Gets a collection containing the values in the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:232
ordered_dictionary(size_t capacity, const xtd::collections::generic::iequality_comparer< key_type > &comparer)
Initializes a new instance of the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:141
auto comparer() const noexcept -> const iequality_comparer< xtd::any_object > &
Definition ordered_dictionary.hpp:206
ordered_dictionary(std::initializer_list< key_value_pair< init_key_t, init_value_t > > init)
Initializes instance of the xtd::collections::generic::ordered_dictionary <key_t, value_t> class from...
Definition ordered_dictionary.hpp:187
typename xtd::collections::generic::idictionary< key_t, value_t >::mapped_type mapped_type
Represents the dictionary mapped type.
Definition ordered_dictionary.hpp:41
typename xtd::collections::generic::idictionary< key_t, value_t >::key_type key_type
Represents the dictionary key type.
Definition ordered_dictionary.hpp:39
ordered_dictionary(input_iterator_t first, input_iterator_t last)
Initializes instance of the xtd::collections::generic::ordered_dictionary <key_t, value_t> class from...
Definition ordered_dictionary.hpp:163
virtual auto items() const noexcept -> const base_type &
Returns the underlying base type items.
Definition ordered_dictionary.hpp:212
xtd::collections::generic::key_value_pair< key_type, mapped_type > base_value_type
Represents the dictionary base value type.
Definition ordered_dictionary.hpp:47
auto contains_key(const key_t &key) const noexcept -> bool override
Determines whether the xtd::collections::generic::ordered_dictionary <key_t, value_t> contains the sp...
Definition ordered_dictionary.hpp:281
auto remove(const key_t &key) noexcept -> bool override
Removes the value with the specified key from the xtd::collections::generic::ordered_dictionary <key_...
Definition ordered_dictionary.hpp:361
auto insert(xtd::size index, const key_t &key, const value_t &value) -> void
Inserts a new entry into the xtd::collections::generic::ordered_dictionary collection with the specif...
Definition ordered_dictionary.hpp:348
ordered_dictionary() noexcept=default
Initializes a new instance of the xtd::collections::generic::ordered_dictionary class.
ordered_dictionary(const xtd::collections::generic::iequality_comparer< key_type > &comparer)
Initializes a new instance of the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:153
ordered_dictionary(ordered_dictionary &&other) noexcept=default
Initializes instance of the xtd::collections::generic::ordered_dictionary <key_t, value_t> class from...
ordered_dictionary(size_t capacity)
Initializes a new instance of the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:128
auto copy_to(xtd::array< value_type > &array, xtd::size array_index) const -> void override
Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array,...
Definition ordered_dictionary.hpp:297
typename xtd::collections::generic::idictionary< key_type, mapped_type >::key_collection key_collection
Represents the idictionary key collection type.
Definition ordered_dictionary.hpp:53
auto keys() const noexcept -> key_collection override
Gets a collection containing the keys in the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:221
ordered_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::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:115
auto try_get_value(const key_t &key, value_t &value) const -> bool override
Gets the value associated with the specified key.
Definition ordered_dictionary.hpp:404
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:115
Contains xtd::collections::generic::dictionary <key_t, value_t> class.
Contains xtd::collections::generic::key_not_found_exception exception.
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
@ invalid_operation
The operation is not valid.
Definition exception_case.hpp:65
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
#define lock_(object)
The lock_ keyword marks a statement block as a critical section by obtaining the mutual-exclusion loc...
Definition lock.hpp:67
constexpr xtd::size npos
Represents a value that is not a valid position in a collection.
Definition npos.hpp:26
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
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:60
@ add
The Add key.
Definition console_key.hpp:170
@ insert
The INS (INSERT) key.
Definition console_key.hpp:62
Contains iteraors aliases.
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
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
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
Contains xtd::threading::lock class.