31 template<
typename key_t,
typename value_t,
typename allocator_t = xtd::collections::
generic::helpers::allocator<std::pair<const key_t, value_t>>>
87 data_->keys.add(item.first);
101 data_->keys.add(item.first);
107 for (
const auto& item : collection)
116 for (
const auto& item : collection)
128 data_->keys.capacity(capacity);
129 data_->items.ensure_capacity(capacity);
142 data_->keys.capacity(capacity);
161 template <
class input_iterator_t >
175 for (
const auto& [key, value] : init)
185 template <
class init_key_t,
typename init_value_t >
187 for (
const auto& [key, value] : init)
200 [[nodiscard]]
auto count() const noexcept ->
size_type override {
return data_->items.count();}
206 return data_->items.comparer();
211 [[nodiscard]]
virtual auto items() const noexcept -> const
base_type& {
return data_->items;}
222 for (
const auto& key : data_->keys)
233 for (
const auto& key : data_->keys)
234 values.add(data_->items[key]);
248 auto add(
const key_t & key,
const value_t& value) ->
void override {
261 auto clear() noexcept ->
void override {
262 lock_(data_->sync_op) {
264 data_->items.clear();
273 return data_->items.contains(item);
280 [[nodiscard]]
auto contains_key(
const key_t & key)
const noexcept ->
bool override {
281 return data_->items.contains_key(key);
289 return data_->items.contains_value(value);
298 for (
const auto& item :
self_)
299 array[array_index++] = item;
305 struct ordered_dictionary_enumerator :
public ienumerator<value_type> {
308 [[nodiscard]]
const value_type& current()
const override {
311 return (value_ =
value_type {key_t {items_.data_->keys[index_]}, value_t {items_.data_->items[items_.data_->keys[index_]]}});
314 [[nodiscard]]
bool move_next()
override {
316 return ++index_ < items_.data_->keys.count();
319 void reset()
override {
320 version_ = items_.data_->version;
349 lock_(data_->sync_op) {
350 data_->items.add(key, value);
351 data_->keys.insert(index, key);
360 auto remove(
const key_t & key)
noexcept ->
bool override {
362 lock_(data_->sync_op) {
373 lock_(data_->sync_op) {
374 auto result = data_->items.remove(item.first);
375 if (!result)
return false;
376 data_->keys.remove_at(get_index(item.first));
388 lock_(data_->sync_op) {
389 data_->items.remove(data_->keys[index]);
390 data_->keys.remove_at(index);
403 [[nodiscard]]
auto try_get_value(
const key_t & key, value_t& value)
const ->
bool override {
404 return data_->items.try_get_value(key, value);
419 *data_ = *
other.data_;
427 for (
const auto& [key, value] : ilist)
434 template <
class init_key_t,
typename init_value_t >
437 for (
const auto& [key, value] : ilist)
466 const value_t&
operator [](
const key_t & key)
const override {
return data_->items[key];}
474 auto iterator = data_->items.items().find(key);
475 if (
iterator != data_->items.items().end())
477 data_->keys.add(key);
478 return data_->items[key];
483 operator const base_type& ()
const noexcept {
return data_->items;}
490 auto get_index(
const key_t & key)
const noexcept ->
xtd::usize {
492 for (
const auto& item_key : data_->keys) {
493 if (item_key == key)
return index;
499 auto is_read_only() const noexcept ->
bool override {
return false;}
501 const xtd::object&
sync_root() const noexcept
override {
return data_->sync_root;}
503 struct dictionary_data {
504 dictionary_data() noexcept = default;
505 dictionary_data(const
base_type & items,
size_type version) noexcept : items {items}, version {version} {
506 for (
const auto& item : this->items)
507 keys.add(item.first);
509 dictionary_data(
base_type&& items,
size_type version) noexcept : items {items}, version {version} {
510 for (
const auto& item : this->items)
511 keys.add(item.first);
517 xtd::object sync_root;
526 template <
class key_t,
typename value_t >
527 ordered_dictionary(xtd::collections::generic::idictionary < key_t, value_t >) -> ordered_dictionary < key_t, value_t>;
529 template <
class key_t,
typename value_t >
532 template <
class key_t,
typename value_t >
533 ordered_dictionary(std::initializer_list < key_value_pair < key_t, value_t>>) -> ordered_dictionary < key_t, value_t >;
535 template <
class key_t,
typename value_t >
536 ordered_dictionary(std::initializer_list < std::pair < key_t, value_t>>) -> ordered_dictionary < key_t, value_t >;
538 template <
class 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:1258
Represents a collection of keys and values.
Definition dictionary.hpp:63
auto keys() const noexcept -> key_collection override
Gets a collection containing the keys in the xtd::collections::generic::dictionary <key_t,...
Definition dictionary.hpp:298
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:285
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 clear() -> void=0
Removes all items from the xtd::collections::generic::icollection <type_t>.
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
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:32
xtd::usize size_type
Represents the dictionary size type.
Definition ordered_dictionary.hpp:44
auto clear() noexcept -> void override
Removes all keys and values from the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:261
const value_t & operator[](const key_t &key) const override
Gets the element with the specified key.
Definition ordered_dictionary.hpp:466
auto insert(xtd::usize 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:347
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:248
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:304
auto to_string() const noexcept -> xtd::string override
Gets a string that represents the current object.
Definition ordered_dictionary.hpp:397
xtd::collections::generic::dictionary< key_type, mapped_type > base_type
Represents the dictionary base type.
Definition ordered_dictionary.hpp:48
typename xtd::collections::generic::idictionary< key_type, mapped_type >::value_collection value_collection
Represents the idictionary value collection type.
Definition ordered_dictionary.hpp:54
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:272
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:200
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:288
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:372
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:106
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:169
xtd::collections::generic::list< key_type > list_type
Represents the dictionary base type.
Definition ordered_dictionary.hpp:50
auto remove_at(xtd::usize index) -> void
Removes the entry at the specified index from the OrderedDictionary collection.
Definition ordered_dictionary.hpp:387
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:97
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:42
auto add(const value_type &item) -> void override
Adds an item to the xtd::collections::generic::icollection <type_t>.
Definition ordered_dictionary.hpp:255
virtual auto items() noexcept -> base_type &
Returns the underlying base type items.
Definition ordered_dictionary.hpp:214
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:231
auto comparer() const noexcept -> const iequality_comparer< xtd::any_object > &
Definition ordered_dictionary.hpp:205
auto operator()(xtd::usize index) const -> const value_t &
Gets the value at the specified index.
Definition ordered_dictionary.hpp:449
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:186
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 ordered_dictionary.hpp:296
typename xtd::collections::generic::idictionary< key_t, value_t >::mapped_type mapped_type
Represents the dictionary mapped type.
Definition ordered_dictionary.hpp:40
typename xtd::collections::generic::idictionary< key_t, value_t >::key_type key_type
Represents the dictionary key type.
Definition ordered_dictionary.hpp:38
auto insert(xtd::usize 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:339
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:162
virtual auto items() const noexcept -> const base_type &
Returns the underlying base type items.
Definition ordered_dictionary.hpp:211
xtd::collections::generic::key_value_pair< key_type, mapped_type > base_value_type
Represents the dictionary base value type.
Definition ordered_dictionary.hpp:46
ordered_dictionary(xtd::usize 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:140
auto operator()(xtd::usize index) -> value_t &
Sets the value at the specified index.
Definition ordered_dictionary.hpp:457
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:280
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:360
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:152
ordered_dictionary(ordered_dictionary &&other) noexcept=default
Initializes instance of the xtd::collections::generic::ordered_dictionary <key_t, value_t> class from...
typename xtd::collections::generic::idictionary< key_type, mapped_type >::key_collection key_collection
Represents the idictionary key collection type.
Definition ordered_dictionary.hpp:52
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:220
ordered_dictionary(xtd::usize capacity)
Initializes a new instance of the xtd::collections::generic::ordered_dictionary <key_t,...
Definition ordered_dictionary.hpp:127
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:114
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:403
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:45
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.
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:68
constexpr auto npos
Represents a value that is not a valid position in a collection.
Definition npos.hpp:26
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 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
auto first() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:249
auto last() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:274
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
Contains xtd::threading::lock class.