9#include <unordered_set>
36 template<
class type_t,
class hasher_t = xtd::collections::
generic::helpers::hasher<type_t>,
class equator_t = xtd::collections::generic::helpers::equator<type_t>,
class allocator_t = xtd::collections::generic::helpers::allocator<type_t >>
49 using base_type = std::unordered_set<key_type, hasher_t, equator_t, allocator_t>;
87 for (
const auto& item : collection)
97 for (
const auto& item : collection)
109 hash_set(
const std::unordered_set<key_type>&
other)
noexcept {
113 hash_set(std::initializer_list <value_type> init) {
115 for (
const auto& value : init)
118 template <
class input_iterator_t>
137 return *data_->comparer;
163 items().insert(item);
170 auto clear() noexcept ->
void override {
210 for (
const auto& item :
self_) {
211 if (increment >= index +
count)
return;
212 if (increment++ >= index)
array[array_index++] = item;
221 return self_.capacity();
228 if (&
other ==
this) {
232 for (
const type_t& item :
other)
239 struct hash_set_enumerator :
public ienumerator < value_type > {
249 bool move_next()
override {
251 if (index_++ && iterator_ != items_.data_->items.cend()) ++iterator_;
252 else iterator_ = items_.items().cbegin();
253 return iterator_ != items_.data_->items.cend();
256 void reset()
override {
258 version_ = items_.data_->version;
259 iterator_ = items_.items().cend();
265 typename hash_set::base_type::const_iterator iterator_ = items_.data_->items.cend();
278 for (
const type_t& item :
self_)
279 if (!to_keep.contains(item))
289 if (
count() == 0)
return set.count() > 0;
290 if (
count() >= set.count())
return false;
299 if (set.count() == 0)
return count() > 0;
300 if (set.count() >=
count())
return false;
301 return super_set(set);
322 if (
count() == 0)
return false;
323 for (
const auto& item :
other)
331 auto remove(
const type_t& item)
noexcept ->
bool override {
332 auto result =
items().erase(item) == 1;
340 template<
class predicate_t>
343 for (
const auto& item :
self_)
344 if (match(item)) to_remove.add(item);
345 for (
const auto& item : to_remove)
347 return to_remove.count();
355 if (
count() != set.count())
return false;
356 for (
const auto& item :
other)
365 for (
const auto& item :
other)
372 auto to_string() const noexcept ->
xtd::
string override {
return xtd::string::format(
"{{{}}}", xtd::string::join(
", ",
self_));}
378 for (
const auto& item :
other)
390 auto is_read_only() const noexcept ->
bool override {
return false;}
391 auto is_synchronized() const noexcept ->
bool override {
return false;}
392 const xtd::object& sync_root() const noexcept
override {
return data_->sync_root;}
393 auto sub_set(
const hash_set& set)
const noexcept ->
bool {
394 if (
count() == 0)
return true;
395 if (
count() > set.count())
return false;
396 for (
const auto& item :
self_)
397 if (!set.contains(item))
return false;
401 auto super_set(
const hash_set& set)
const noexcept ->
bool {
402 if (set.count() == 0)
return true;
403 if (set.count() >
count())
return false;
404 for (
const auto& item : set)
409 struct hash_set_data {
410 hash_set_data() =
default;
411 hash_set_data(
const xtd::collections::generic::iequality_comparer<key_type>& comparer) : comparer {&comparer}, items {
size_type {}, hasher_t {*comparer}, equator_t {*comparer}, allocator_t {}} {}
412 hash_set_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}, allocator_t {}}, version {version} {
413 for (
const auto& item : items)
414 self_.items.insert(item);
417 for (
auto&& item : items)
418 self_.items.insert(item);
421 const xtd::collections::generic::iequality_comparer<key_type>* comparer =
null;
424 xtd::object sync_root;
432 template<
class type_t>
435 template<
class type_t>
438 template <
class type_t>
441 template <
class input_iterator_t >
Contains xtd::collections::generic::helpers::allocator alias.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
virtual size_type length() const noexcept
Gets a size that represents the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:124
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
Represents a set of values.
Definition hash_set.hpp:37
auto contains(const value_type &item) const noexcept -> bool override
Determines whether an element is in the xtd::collections::generic::dictionary <key_t,...
Definition hash_set.hpp:178
typename xtd::collections::generic::iset< type_t >::value_type value_type
Represents the hash set value type.
Definition hash_set.hpp:45
auto intersect_with(const xtd::collections::generic::ienumerable< type_t > &other) noexcept -> void override
Modifies the current set so that it contains only elements that are also in a specified collection.
Definition hash_set.hpp:275
auto symetric_excep_with(const xtd::collections::generic::ienumerable< type_t > &other) noexcept -> void override
Modifies the current set so that it contains only elements that are present either in the current set...
Definition hash_set.hpp:364
auto capacity() const noexcept -> size_type
Gets the total numbers of elements the internal data structure can hold without resizing.
Definition hash_set.hpp:130
auto except_with(const xtd::collections::generic::ienumerable< type_t > &other) noexcept -> void override
Removes all elements in the specified collection from the current set.
Definition hash_set.hpp:227
auto overlaps(const xtd::collections::generic::ienumerable< type_t > &other) const noexcept -> bool override
Determines whether the current set overlaps with the specified collection.
Definition hash_set.hpp:321
auto set_equals(const xtd::collections::generic::ienumerable< type_t > &other) const noexcept -> bool override
Determines whether the current set and the specified collection contain the same elements.
Definition hash_set.hpp:353
auto copy_to(size_type index, xtd::array< type_t > &array, size_type array_index, size_type count) const -> void
Copies a specified number of elements from hash_set <type_t> to a compatible one-dimensional array,...
Definition hash_set.hpp:207
auto is_proper_superset_of(const xtd::collections::generic::ienumerable< type_t > &other) const noexcept -> bool override
Determines whether the current set is a proper (strict) superset of a specified collection.
Definition hash_set.hpp:297
auto is_superset_of(const xtd::collections::generic::ienumerable< type_t > &other) const noexcept -> bool override
Determines whether a set is a superset of a specified collection.
Definition hash_set.hpp:314
hash_set(const ienumerable< value_type > &collection) noexcept
Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that uses the de...
Definition hash_set.hpp:86
auto is_subset_of(const xtd::collections::generic::ienumerable< type_t > &other) const noexcept -> bool override
Determines whether a set is a subset of a specified collection.
Definition hash_set.hpp:307
xtd::size size_type
Represents the hash set size type.
Definition hash_set.hpp:47
auto to_string() const noexcept -> xtd::string override
Gets a string that represents the current object.
Definition hash_set.hpp:372
virtual auto items() const noexcept -> const base_type &
Returns the underlying base type items.
Definition hash_set.hpp:149
hash_set() noexcept=default
Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that is empty an...
auto clear() noexcept -> void override
Removes all keys and values from the xtd::collections::generic::dictionary <key_t,...
Definition hash_set.hpp:170
auto copy_to(xtd::array< type_t > &array, size_type index) const -> void override
Copies the complete hash_set <type_t> to a compatible one-dimensional array, starting at the specifie...
Definition hash_set.hpp:196
auto copy_to(xtd::array< type_t > &array) const -> void
Copies the complete hash_set <type_t> to a compatible one-dimensional array, starting at the beginnin...
Definition hash_set.hpp:186
auto union_with(const xtd::collections::generic::ienumerable< type_t > &other) noexcept -> void override
Modifies the current set so that it contains all elements that are present in the current set,...
Definition hash_set.hpp:377
auto remove(const type_t &item) noexcept -> bool override
Removes a specified item from the hash_set <type_t>.
Definition hash_set.hpp:331
auto ensure_capacity(xtd::size capacity) noexcept -> xtd::size
Ensures that the dictionary can hold up to a specified number of entries without any further expansio...
Definition hash_set.hpp:219
virtual auto items() noexcept -> base_type &
Returns the underlying base type items.
Definition hash_set.hpp:152
std::unordered_set< key_type, hasher_t, equator_t, allocator_t > base_type
Represents the hash set base type.
Definition hash_set.hpp:49
hash_set(size_type capacity) noexcept
Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that is empty,...
Definition hash_set.hpp:103
auto remove_where(predicate_t match) noexcept -> size_type
Removes all elements that match the conditions defined by the specified predicate from a hash_set <ty...
Definition hash_set.hpp:341
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::hash_set <type_t>.
Definition hash_set.hpp:238
auto add(const key_type &item) noexcept -> bool override
Adds an item to the xtd::collections::generic::icollection <type_t>.
Definition hash_set.hpp:161
auto is_proper_subset_of(const xtd::collections::generic::ienumerable< type_t > &other) const noexcept -> bool override
Determines whether the current set is a proper (strict) superset of a specified collection.
Definition hash_set.hpp:287
auto comparer() const noexcept -> const iequality_comparer< key_type > &
Gets the xtd::collections::generic::iequality_comparer <type_t> that is used to determine equality of...
Definition hash_set.hpp:135
auto count() const noexcept -> size_type override
Gets the number of key/value pairs contained in the xtd::collections::generic::dictionary <key_t,...
Definition hash_set.hpp:145
hash_set(const ienumerable< value_type > &collection, const xtd::collections::generic::iequality_comparer< key_type > &comparer) noexcept
Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that uses the sp...
Definition hash_set.hpp:96
typename xtd::collections::generic::iset< type_t >::key_type key_type
Represents the hash set key type.
Definition hash_set.hpp:43
friend class ienumerable
Exposes an enumerator, which supports a simple iteration over a non-generic collection.
Definition ienumerable_abstract.hpp:38
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
typename xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition ienumerable.hpp:48
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
Provides the base interface for the abstraction of sets.
Definition iset.hpp:33
type_t value_type
Represents the set value type.
Definition iset.hpp:41
typename icollection< type_t >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition iset.hpp:43
type_t key_type
Represents the set key type.
Definition iset.hpp:39
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::helpers::equator struct.
@ 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
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
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
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
Contains xtd::collections::generic::helpers::hasher struct.
Contains xtd::collections::generic::iset <type_t> interface.
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