xtd 0.2.0
Loading...
Searching...
No Matches
xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t > Class Template Reference
Inheritance diagram for xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >:
xtd::object xtd::collections::generic::iset< type_t > xtd::collections::generic::ienumerable< type_t > xtd::interface xtd::collections::generic::ienumerable_abstract xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > > xtd::collections::generic::extensions::enumerable< ienumerable< type_t >, type_t >

Definition

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 >>
class xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >

Represents a set of values.

Definition
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 >>
hash_set() noexcept=default
Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that is empty an...
Provides the base interface for the abstraction of sets.
Definition iset.hpp:33
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
std::allocator< type_t > allocator
Represent an allocator alias.
Definition allocator.hpp:38
Implements a function object for performing comparisons. Unless specialised, invokes operator== on ty...
Definition equator.hpp:39
Header
#include <xtd/collections/generic/hash_set>
Namespace
xtd::collections::generic
Library
xtd.core
Remarks
The xtd::collections::generic::hash_set class is same as std::unordered_set.
Examples
The following example demonstrates how to merge two disparate sets. This example creates two xtd::collections::generic::hash_set <type_t> objects and populates them with even and odd numbers, respectively. A third xtd::collections::generic::hash_set <type_t> object is created from the set that contains the even numbers. The example then calls the xtd::collections::generic::hash_set::union_with method, which adds the odd number set to the third set.
#include <xtd/xtd>
namespace examples {
class program {
public:
static void main() {
auto even_numbers = hash_set<int> {};
auto odd_numbers = hash_set<int> {};
for (auto i = 0; i < 5; ++i) {
// Populate even_numbers with just even numbers.
even_numbers.add(i * 2);
// Populate odd_numbers with just odd numbers.
odd_numbers.add((i * 2) + 1);
}
console::write("even_numbers contains {} elements: ", even_numbers.count());
display_set(even_numbers);
console::write("odd_numbers contains {} elements: ", odd_numbers.count());
display_set(odd_numbers);
// Create a new hash_set populated with even numbers.
auto numbers = even_numbers;
console::write_line("numbers union_with odd_numbers...");
numbers.union_with(odd_numbers);
console::write("numbers contains {} elements: ", numbers.count());
display_set(numbers);
}
private:
static void display_set(const hash_set<int>& collection) {
console::write("{");
for (auto i : collection)
console::write(" {}", i);
console::write_line(" }");
}
};
}
startup_(examples::program::main);
// This code can produce the following output :
//
// even_numbers contains 5 elements: { 8 6 4 2 0 }
// odd_numbers contains 5 elements: { 9 7 5 3 1 }
// numbers union_with odd_numbers...
// numbers contains 10 elements: { 1 3 5 7 9 0 2 4 6 8 }
Represents a set of values.
Definition hash_set.hpp:37
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:462
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:168
@ i
The I key.
Definition console_key.hpp:104

Public Aliases

using key_type
 Represents the hash set key type.
 
using value_type
 Represents the hash set value type.
 
using size_type
 Represents the hash set size type.
 
using base_type
 Represents the hash set base type.
 

Public Constructors

 hash_set () noexcept=default
 Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that is empty and uses the default equality comparer for the set type.
 
 hash_set (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 is empty and uses the specified equality comparer for the set type.
 
 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 default equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.
 
 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 specified equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.
 
 hash_set (size_type capacity) noexcept
 Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that is empty, but has reserved space for capacity items and uses the default equality comparer for the set type.
 
 hash_set (hash_set &&other) noexcept=default
 
 hash_set (const hash_set &other) noexcept
 
 hash_set (std::unordered_set< key_type > &&other) noexcept
 
 hash_set (const std::unordered_set< key_type > &other) noexcept
 
 hash_set (std::initializer_list< value_type > init)
 
template<class input_iterator_t>
 hash_set (input_iterator_t first, input_iterator_t last)
 

Public Properties

auto capacity () const noexcept -> size_type
 Gets the total numbers of elements the internal data structure can hold without resizing.
 
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 keys for the set.
 
auto count () const noexcept -> size_type override
 Gets the number of key/value pairs contained in the xtd::collections::generic::dictionary <key_t, value_t>.
 
virtual auto items () const noexcept -> const base_type &
 Returns the underlying base type items.
 
virtual auto items () noexcept -> base_type &
 Returns the underlying base type items.
 

Public Methods

auto add (const key_type &item) noexcept -> bool override
 Adds an item to the xtd::collections::generic::icollection <type_t>.
 
auto clear () noexcept -> void override
 Removes all keys and values from the xtd::collections::generic::dictionary <key_t, value_t>.
 
auto contains (const value_type &item) const noexcept -> bool override
 Determines whether an element is in the xtd::collections::generic::dictionary <key_t, value_t>.
 
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 beginning of the target array.
 
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 specified array index.
 
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, starting at the specified array index.
 
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 expansion of its backing storage.
 
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.
 
enumerator< value_typeget_enumerator () const noexcept override
 Returns an enumerator that iterates through the xtd::collections::generic::hash_set <type_t>.
 
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.
 
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.
 
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.
 
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.
 
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.
 
auto overlaps (const xtd::collections::generic::ienumerable< type_t > &other) const noexcept -> bool override
 Determines whether the current set overlaps with the specified collection.
 
auto remove (const type_t &item) noexcept -> bool override
 Removes a specified item from the hash_set <type_t>.
 
template<class predicate_t>
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 <type_t> collection.
 
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.
 
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 or in the specified collection, but not both.
 
auto to_string () const noexcept -> xtd::string override
 Gets a string that represents the current object.
 
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, in the specified collection, or in both.
 

Additional Inherited Members

using key_type
 Represents the set key type.
 
using value_type
 Represents the set value type.
 
using iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
 
using const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
 
using value_type
 Represents the xtd::collections::generic::ienumerable value type.
 
using iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
 
using const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
 
using iterator
 Represents the iterator of enumerable value type.
 
using const_iterator
 Represents the const iterator of enumerable value type.
 
using enumerable_type
 Represents the ienumerable enumerable type.
 
using source_type
 Represents the ienumerable source type.
 
using ienumerable
 Represents the ienumerable value type.
 
using list
 Represents the list value type.
 
 object ()=default
 Create a new instance of the ultimate base class object.
 
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.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual auto begin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
 
virtual auto begin () -> iterator
 Returns an iterator to the first element of the enumerable.
 
virtual auto cbegin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
 
virtual auto cend () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
 
virtual auto end () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
 
virtual auto end () -> iterator
 Returns an iterator to the element following the last element of the enumerable.
 
auto aggregate (const std::function< type_t(const type_t &, const type_t &)> &func) const -> type_t
 Applies an accumulator function over a sequence.
 
auto aggregate (const type_t &seed, const std::function< type_t(const type_t &, const type_t &)> &func) const -> type_t
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
auto aggregate (const accumulate_t &seed, const std::function< accumulate_t(const accumulate_t &, const type_t &)> &func) const -> accumulate_t
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
auto aggregate (const type_t &seed, const std::function< type_t(const type_t &, const type_t &)> &func, const std::function< type_t(const type_t &)> &result_selector) const -> type_t
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
auto aggregate (const accumulate_t &seed, const std::function< accumulate_t(const accumulate_t &, const type_t &)> &func, const std::function< result_t(const accumulate_t &)> &result_selector) const -> result_t
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
auto all (const std::function< bool(const type_t &)> &predicate) const -> bool
 Determines whether all elements of a sequence satisfy a condition.
 
auto any () const noexcept -> bool
 Determines whether a sequence contains any elements.
 
auto any (const std::function< bool(const type_t &)> &predicate) const -> bool
 Determines whether any element of a sequence satisfies a condition.
 
auto append (const type_t &element) const noexcept
 Appends a value to the end of the sequence.
 
auto as_enumerable () const noexcept
 Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
 
auto average () const noexcept
 Computes the average of a sequence of source_t values.
 
auto cast () const noexcept
 Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
 
auto chunk (size_t size) const
 Splits the elements of a sequence into chunks of size at most size.
 
auto concat (const ienumerable< type_t > &second) const noexcept
 Concatenates two sequences.
 
auto contains (const type_t &value) const noexcept -> bool
 Determines whether a sequence contains a specified element by using the default equality comparer.
 
auto contains (const type_t &value, const xtd::collections::generic::iequality_comparer< type_t > &comparer) const noexcept -> bool
 Determines whether a sequence contains a specified element by using a specified equality comparer.
 
auto count () const noexcept -> xtd::size
 Returns the number of elements in current sequence.
 
auto count (const std::function< bool(const type_t &)> &predicate) const noexcept -> xtd::size
 Returns a number that represents how many elements in the specified sequence satisfy a condition.
 
auto count (const type_t &value) const noexcept -> xtd::size
 Returns the number of elements with the specified value.
 
auto count_by (const std::function< key_t(const type_t &)> &key_selector) const noexcept
 Returns the count of elements in the current sequence grouped by key.
 
auto count_by (const std::function< key_t(const type_t &)> &key_selector, const iequality_comparer< key_t > &key_comparer) const noexcept
 Returns the count of elements in the current sequence grouped by key.
 
auto default_if_empty () const noexcept
 Returns the elements of the specified sequence or the type parameter's default value in a singleton collection if the current sequence is empty.
 
auto default_if_empty (const type_t &default_value) const noexcept
 Returns the elements of the specified sequence or the specified value in a singleton collection if the current sequence is empty.
 
auto distinct () const noexcept
 Returns distinct elements from a sequence by using the default equality comparer to compare values.
 
auto distinct (const xtd::collections::generic::iequality_comparer< type_t > &comparer) const noexcept
 Returns distinct elements from a sequence by using a specified xtd::collections::generic::iequality_comparer <type_t> to compare values.
 
auto first_or_default (const std::function< bool(const type_t &)> &predicate, const type_t &default_value) const noexcept -> type_t
 Returns the first element of the sequence that satisfies a condition, or a specified default value if no such element is found.
 
auto first_or_default (const std::function< bool(const type_t &)> &predicate) const noexcept -> type_t
 Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
 
auto first_or_default (const type_t default_value) const noexcept -> type_t
 Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
 
auto first_or_default () const noexcept -> type_t
 Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
 
auto order ()
 Sorts the elements of a sequence in ascending order.
 
auto order (const xtd::collections::generic::icomparer< type_t > &comparer)
 Sorts the elements of a sequence in ascending order.
 
auto order_by (const std::function< type_t(const type_t &)> &key_selector) const
 Sorts the elements of a sequence in ascending order according to a key.
 
auto order_by (const std::function< key_t(const type_t &)> &key_selector) const
 Sorts the elements of a sequence in ascending order according to a key.
 
auto order_by_descending (const std::function< key_t(const type_t &)> &key_selector) const
 Sorts the elements of a sequence in descending order according to a key.
 
auto order_by_descending (const std::function< type_t(const type_t &)> &key_selector) const
 Sorts the elements of a sequence in descending order according to a key.
 
auto select (const std::function< result_t(const type_t &)> &selector) const
 Projects each element of a sequence into a new form.
 
auto select (const std::function< type_t(const type_t &)> &selector) const
 Projects each element of a sequence into a new form.
 
auto select (const std::function< result_t(const type_t &, size_t index)> &selector) const
 Projects each element of a sequence into a new form by incorporating the element's index.
 
auto select (const std::function< type_t(const type_t &, size_t index)> &selector) const
 Projects each element of a sequence into a new form by incorporating the element's index.
 
auto to_array () const noexcept -> xtd::array< type_t >
 Creates a xtd::array <type_t> from an xtd::collections::generic::ienumerable <type_t>.
 
auto to_list () const noexcept -> list< type_t >
 Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <type_t>.
 
auto where (const std::function< bool(const type_t &)> &predicate) const
 Filters a sequence of values based on a predicate.
 
auto where (const std::function< bool(const type_t &, size_t)> &predicate) const
 Filters a sequence of values based on a predicate. Each element's index is used in the logic of the predicate function.
 
template<class object_a_t, class object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<class object_a_t, class object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
static auto to_const_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.
 
static auto to_const_iterator (typename source_collection_t::const_iterator &value, source_collection_t &source_collection, target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.
 
static auto to_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.
 
static auto to_iterator (typename source_collection_t::iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::iterator
 Converts source iterator to target iterator.
 
static auto to_iterator (typename source_collection_t::const_iterator &value, source_collection_t &source_collection, target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.
 
static auto to_iterator (typename source_collection_t::iterator &value, source_collection_t &source_collection, target_collection_t &target_collection) noexcept -> typename target_collection_t::iterator
 Converts source iterator to target iterator.
 

Member Typedef Documentation

◆ key_type

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 >>
using xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::key_type

Represents the hash set key type.

◆ value_type

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 >>
using xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::value_type

Represents the hash set value type.

◆ size_type

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 >>
using xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::size_type

Represents the hash set size type.

◆ base_type

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 >>
using xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::base_type

Represents the hash set base type.

Constructor & Destructor Documentation

◆ hash_set() [1/5]

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 >>
xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::hash_set ( )
defaultnoexcept

Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that is empty and uses the default equality comparer for the set type.

Examples
The following example demonstrates how to create and populate two xtd::collections::generic::hash_set <type_t> objects. This example is part of a larger example provided for the xtd::collections::generic::hash_set::union_with method.
auto even_numbers = hash_set<int> {};
auto odd_numbers = hash_set<int> {};
for (auto i = 0; i < 5; ++i) {
// Populate even_numbers with just even numbers.
even_numbers.add(i * 2);
// Populate odd_numbers with just odd numbers.
odd_numbers.add((i * 2) + 1);
}
Remarks
The capacity of a xtd::collections::generic::hash_set <type_t> object is the number of elements that the object can hold. A xtd::collections::generic::hash_set <type_t> object's capacity automatically increases as elements are added to the object.
This constructor is an O(1) operation.

◆ hash_set() [2/5]

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 >>
xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::hash_set ( const xtd::collections::generic::iequality_comparer< key_type > & comparer)
inlinenoexcept

Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that is empty and uses the specified equality comparer for the set type.

Parameters
comparerThe xtd::collections::generic::iequality_comparer <type_t> implementation to use when comparing values in the set.
Remarks
The capacity of a xtd::collections::generic::hash_set <type_t> object is the number of elements that the object can hold. A xtd::collections::generic::hash_set <type_t> object's capacity automatically increases as elements are added to the object.
This constructor is an O(1) operation.

◆ hash_set() [3/5]

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 >>
xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::hash_set ( const ienumerable< value_type > & collection)
inlinenoexcept

Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that uses the default equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.

Parameters
collectionThe collection whose elements are copied to the new set.
Examples
The following example shows how to create a xtd::collections::generic::hash_set <type_t> collection from an existing set. In this example, two sets are created with even and odd integers, respectively. A third xtd::collections::generic::hash_set <type_t> object is then created from the even integer set.
#include <xtd/xtd>
namespace examples {
class program {
public:
static void main() {
auto even_numbers = hash_set<int> {};
auto odd_numbers = hash_set<int> {};
for (auto i = 0; i < 5; ++i) {
// Populate even_numbers with just even numbers.
even_numbers.add(i * 2);
// Populate odd_numbers with just odd numbers.
odd_numbers.add((i * 2) + 1);
}
console::write("even_numbers contains {} elements: ", even_numbers.count());
display_set(even_numbers);
console::write("odd_numbers contains {} elements: ", odd_numbers.count());
display_set(odd_numbers);
// Create a new hash_set populated with even numbers.
auto numbers = even_numbers;
console::write_line("numbers union_with odd_numbers...");
numbers.union_with(odd_numbers);
console::write("numbers contains {} elements: ", numbers.count());
display_set(numbers);
}
private:
static void display_set(const hash_set<int>& collection) {
console::write("{");
for (auto i : collection)
console::write(" {}", i);
console::write_line(" }");
}
};
}
startup_(examples::program::main);
// This code can produce the following output :
//
// even_numbers contains 5 elements: { 8 6 4 2 0 }
// odd_numbers contains 5 elements: { 9 7 5 3 1 }
// numbers union_with odd_numbers...
// numbers contains 10 elements: { 1 3 5 7 9 0 2 4 6 8 }
Remarks
The capacity of a xtd::collections::generic::hash_set <type_t> object is the number of elements that the object can hold. A xtd::collections::generic::hash_set <type_t> object's capacity automatically increases as elements are added to the object.
If collection contains duplicates, the set will contain one of each unique element. No exception will be thrown. Therefore, the size of the resulting set is not identical to the size of collection.
This constructor is an O(n) operation, where n is the number of elements in the collection parameter.

◆ hash_set() [4/5]

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 >>
xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::hash_set ( const ienumerable< value_type > & collection,
const xtd::collections::generic::iequality_comparer< key_type > & comparer )
inlinenoexcept

Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that uses the specified equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.

Parameters
collectionThe collection whose elements are copied to the new set.
comparerThe xtd::collections::generic::iequality_comparer <type_t> implementation to use when comparing values in the set.
Examples
The following example uses a supplied xtd::collections::generic::iequality_comparer <type_t> to allow case-insensitive comparisons on the elements of a xtd::collections::generic::hash_set <type_t> collection of vehicle types.
#include <xtd/xtd>
class example {
public:
static void main() {
auto some_vehicles = list<string> {};
some_vehicles.add("Planes");
some_vehicles.add("Trains");
some_vehicles.add("Automobiles");
// Add in the vehicles contained in the some_vehicles list.
all_vehicles.union_with(some_vehicles);
console::write_line("The current hash_set contains:\n");
for (auto vehicle : all_vehicles)
all_vehicles.add("Ships");
all_vehicles.add("Motorcycles");
all_vehicles.add("Rockets");
all_vehicles.add("Helicopters");
all_vehicles.add("Submarines");
console::write_line("\nThe updated hash_set contains:\n");
for (auto vehicle : all_vehicles)
// Verify that the 'All Vehicles' set contains at least the vehicles in
// the 'Some Vehicles' list.
if (all_vehicles.is_superset_of(some_vehicles)) {
console::write("\nThe 'All' vehicles set contains everything in ");
console::write_line("'Some' vechicles list.");
}
// Check for Rockets. Here the OrdinalIgnoreCase comparer will compare
// true for the mixed-case vehicle type.
if (all_vehicles.contains("roCKeTs"))
console::write_line("\nThe 'All' vehicles set contains 'roCKeTs'");
all_vehicles.except_with(some_vehicles);
console::write_line("\nThe excepted hash_set contains:\n");
for (auto vehicle : all_vehicles)
// Remove all the vehicles that are not 'super cool'.
all_vehicles.remove_where(is_not_super_cool);
console::write_line("\nThe super cool vehicles are:\n");
for (auto vehicle : all_vehicles)
}
// Predicate to determine vehicle 'coolness'.
static bool is_not_super_cool(const string& vehicle) {
bool super_cool = (vehicle == "Helicopters") || (vehicle == "Motorcycles");
return !super_cool;
}
};
startup_(example::main);
// This code produces the following output :
//
// The current hash_set contains:
//
// Trains
// Automobiles
// Planes
//
// The updated hash_set contains:
//
// Submarines
// Helicopters
// Ships
// Rockets
// Motorcycles
// Trains
// Automobiles
// Planes
//
// The 'All' vehicles set contains everything in 'Some' vechicles list.
//
// The 'All' vehicles set contains 'roCKeTs'
//
// The excepted hash_set contains:
//
// Submarines
// Helicopters
// Ships
// Rockets
// Motorcycles
//
// The super cool vehicles are:
//
// Helicopters
// Motorcycles
static const basic_string_comparer & ordinal_ignore_case()
Definition basic_string_comparer.hpp:104
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
auto add(const type_t &item) -> void override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:273

◆ hash_set() [5/5]

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 >>
xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::hash_set ( size_type capacity)
inlinenoexcept

Initializes a new instance of the xtd::collections::generic::hash_set <type_t> class that is empty, but has reserved space for capacity items and uses the default equality comparer for the set type.

Parameters
capacityThe initial size of the xtd::collections::generic::hash_set <type_t>.
Remarks
Since resizes are relatively expensive (require rehashing), this attempts to minimize the need to resize by setting the initial capacity based on the value of the capacity.

Member Function Documentation

◆ capacity()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::capacity ( ) const -> size_type
inlinenoexcept

Gets the total numbers of elements the internal data structure can hold without resizing.

Returns
The total numbers of elements the internal data structure can hold without resizing.

◆ comparer()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::comparer ( ) const -> const iequality_comparer<key_type>&
inlinenoexcept

Gets the xtd::collections::generic::iequality_comparer <type_t> that is used to determine equality of keys for the set.

Returns
The xtd::collections::generic::iequality_comparer <type_t> generic interface implementation that is used to determine equality of keys for the current xtd::collections::generic::hash_set <type_t> and to provide hash values for the keys.
Remarks
xtd::collections::generic::hash_set <type_t> requires an equality implementation to determine whether keys are equal. You can specify an implementation of the xtd::collections::generic::iequality_comparer <type_t> generic interface by using a constructor that accepts a comparer parameter; if you do not specify one, the default generic equality comparer td::collections::generic::equality_comparer::default_equality_comparer is used.

◆ count()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::count ( ) const -> size_type
inlineoverridevirtualnoexcept

Gets the number of key/value pairs contained in the xtd::collections::generic::dictionary <key_t, value_t>.

Returns
the number of key/value pairs contained in the xtd::collections::generic::dictionary <key_t, value_t>.
Remarks
The capacity of a xtd::collections::generic::dictionary <key_t, value_t> is the number of elements that the xtd::collections::generic::dictionary <key_t, value_t> can store. The xtd::collections::generic::dictionary::count property is the number of elements that are actually in the xtd::collections::generic::dictionary <key_t, value_t>.
The capacity is always greater than or equal to xtd::collections::generic::dictionary::count. If xtd::collections::generic::dictionary::count exceeds the capacity while adding elements, the capacity is increased by automatically reallocating the internal array before copying the old elements and adding the new elements.
Getting the value of this property is an O(1) operation.

Implements xtd::collections::generic::iset< type_t >.

◆ items() [1/2]

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 >>
virtual auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::items ( ) const -> const base_type&
inlinevirtualnoexcept

Returns the underlying base type items.

Returns
The underlying base type items.

◆ items() [2/2]

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 >>
virtual auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::items ( ) -> base_type&
inlinevirtualnoexcept

Returns the underlying base type items.

Returns
The underlying base type items.

◆ add()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::add ( const key_type & item) -> bool
inlineoverridevirtualnoexcept

Adds an item to the xtd::collections::generic::icollection <type_t>.

Parameters
itemThe object to add to the xtd::collections::generic::icollection <type_t>.
Exceptions
xtd::not_supported_exceptionThe xtd::collections::generic::icollection <type_t> is read-only.

Implements xtd::collections::generic::iset< type_t >.

◆ clear()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::clear ( ) -> void
inlineoverridevirtualnoexcept

Removes all keys and values from the xtd::collections::generic::dictionary <key_t, value_t>.

Remarks
The xtd::collections::generic::dictionary::count property is set to 0, and references to other objects from elements of the collection are also released. The capacity remains unchanged.

Implements xtd::collections::generic::iset< type_t >.

◆ contains()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::contains ( const value_type & item) const -> bool
inlineoverridevirtualnoexcept

Determines whether an element is in the xtd::collections::generic::dictionary <key_t, value_t>.

Parameters
itemThe object to be added to the end of the xtd::collections::generic::dictionary <key_t, value_t>.
Returns
true if the xtd::collections::generic::dictionary <key_t, value_t> contains an element with the specified item ; otherwise, false.

Implements xtd::collections::generic::iset< type_t >.

◆ copy_to() [1/3]

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::copy_to ( xtd::array< type_t > & array) const -> void
inline

Copies the complete hash_set <type_t> to a compatible one-dimensional array, starting at the beginning of the target array.

Parameters
arrayA one-dimensional array that is the destination of the elements copied from the hash_set <type_t>.
Exceptions
ArgumentExceptionThe number of elements in the source hash_set <type_t> exceeds the number of elements that the destination array can contain.
ArgumentNullExceptionarray is null.

◆ copy_to() [2/3]

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::copy_to ( xtd::array< type_t > & array,
size_type index ) const -> void
inlineoverridevirtual

Copies the complete hash_set <type_t> to a compatible one-dimensional array, starting at the specified array index.

Parameters
arrayA one-dimensional array that is the destination of the elements copied from the hash_set <type_t>. The array must have zero-based indexing.
indexThe zero-based index in array at which copying begins.
Exceptions
ArgumentExceptionThe number of elements in the source array is greater than the available space from index to the end of the destination array.
ArgumentNullExceptionarray is null.
ArgumentOutOfRangeExceptionindex is less than zero.

Implements xtd::collections::generic::iset< type_t >.

◆ copy_to() [3/3]

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::copy_to ( size_type index,
xtd::array< type_t > & array,
size_type array_index,
size_type count ) const -> void
inline

Copies a specified number of elements from hash_set <type_t> to a compatible one-dimensional array, starting at the specified array index.

Parameters
arrayA one-dimensional array that is the destination of the elements copied from the hash_set <type_t>. The array must have zero-based indexing.
indexThe zero-based index in array at which copying begins.
countThe number of elements to copy.
Exceptions
ArgumentExceptionThe number of elements in the source (count) array is greater than the available space from index to the end of the destination array.
ArgumentNullExceptionarray is null.
ArgumentOutOfRangeExceptionindex is less than zero or count is less than zero.

◆ ensure_capacity()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::ensure_capacity ( xtd::size capacity) -> xtd::size
inlinenoexcept

Ensures that the dictionary can hold up to a specified number of entries without any further expansion of its backing storage.

Parameters
capacityThe number of entries.
Returns
The current capacity of the xtd::collections::generic::dictionary <key_t, value_t>.

◆ except_with()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::except_with ( const xtd::collections::generic::ienumerable< type_t > & other) -> void
inlineoverridevirtualnoexcept

Removes all elements in the specified collection from the current set.

Parameters
otherThe collection of items to remove from the set.
Remarks
This method is an O(n) operation, where n is the number of elements in the other parameter.

Implements xtd::collections::generic::iset< type_t >.

◆ get_enumerator()

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 >>
enumerator< value_type > xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::get_enumerator ( ) const
inlineoverridevirtualnoexcept

Returns an enumerator that iterates through the xtd::collections::generic::hash_set <type_t>.

Returns
A xtd::collections::enumerator structure for the xtd::collections::generic::hash_set <type_t>.

Implements xtd::collections::generic::ienumerable< type_t >.

◆ intersect_with()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::intersect_with ( const xtd::collections::generic::ienumerable< type_t > & other) -> void
inlineoverridevirtualnoexcept

Modifies the current set so that it contains only elements that are also in a specified collection.

Parameters
otherThe collection to compare to the current set.
Remarks
This method ignores any duplicate elements in other.

Implements xtd::collections::generic::iset< type_t >.

◆ is_proper_subset_of()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::is_proper_subset_of ( const xtd::collections::generic::ienumerable< type_t > & other) const -> bool
inlineoverridevirtualnoexcept

Determines whether the current set is a proper (strict) superset of a specified collection.

Parameters
otherThe collection to compare to the current set.
Returns
true if the current set is a proper superset of other; otherwise, false.

Implements xtd::collections::generic::iset< type_t >.

◆ is_proper_superset_of()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::is_proper_superset_of ( const xtd::collections::generic::ienumerable< type_t > & other) const -> bool
inlineoverridevirtualnoexcept

Determines whether the current set is a proper (strict) superset of a specified collection.

Parameters
otherThe collection to compare to the current set.
Returns
true if the current set is a proper superset of other; otherwise, false.

Implements xtd::collections::generic::iset< type_t >.

◆ is_subset_of()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::is_subset_of ( const xtd::collections::generic::ienumerable< type_t > & other) const -> bool
inlineoverridevirtualnoexcept

Determines whether a set is a subset of a specified collection.

Parameters
otherThe collection to compare to the current set.
Returns
true if the current set is a subset of other; otherwise, false.

Implements xtd::collections::generic::iset< type_t >.

◆ is_superset_of()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::is_superset_of ( const xtd::collections::generic::ienumerable< type_t > & other) const -> bool
inlineoverridevirtualnoexcept

Determines whether a set is a superset of a specified collection.

Parameters
otherThe collection to compare to the current set.
Returns
true if the current set is a superset of other; otherwise, false.

Implements xtd::collections::generic::iset< type_t >.

◆ overlaps()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::overlaps ( const xtd::collections::generic::ienumerable< type_t > & other) const -> bool
inlineoverridevirtualnoexcept

Determines whether the current set overlaps with the specified collection.

Parameters
otherThe collection to compare to the current set.
Returns
true if the current set and other share at least one common element; otherwise, false.

Implements xtd::collections::generic::iset< type_t >.

◆ remove()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::remove ( const type_t & item) -> bool
inlineoverridevirtualnoexcept

Removes a specified item from the hash_set <type_t>.

Parameters
itemThe element to remove.
Returns
true if the element was removed, false otherwise.

Implements xtd::collections::generic::iset< type_t >.

◆ remove_where()

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 >>
template<class predicate_t>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::remove_where ( predicate_t match) -> size_type
inlinenoexcept

Removes all elements that match the conditions defined by the specified predicate from a hash_set <type_t> collection.

Parameters
matchThe xtd::predicate <type_t> delegate that defines the conditions of the elements to remove.
Returns
The number of elements that were removed from the hash_set <type_t> collection.

◆ set_equals()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::set_equals ( const xtd::collections::generic::ienumerable< type_t > & other) const -> bool
inlineoverridevirtualnoexcept

Determines whether the current set and the specified collection contain the same elements.

Parameters
otherThe collection to compare to the current set.
Returns
true if the current set is equal to other; otherwise, false.

Implements xtd::collections::generic::iset< type_t >.

◆ symetric_excep_with()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::symetric_excep_with ( const xtd::collections::generic::ienumerable< type_t > & other) -> void
inlineoverridevirtualnoexcept

Modifies the current set so that it contains only elements that are present either in the current set or in the specified collection, but not both.

Parameters
otherThe collection to compare to the current set.
Remarks
Any duplicate elements in other are ignored.

Implements xtd::collections::generic::iset< type_t >.

◆ to_string()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::to_string ( ) const -> xtd::string
inlineoverridevirtualnoexcept

Gets a string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.

◆ union_with()

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 >>
auto xtd::collections::generic::hash_set< type_t, hasher_t, equator_t, allocator_t >::union_with ( const xtd::collections::generic::ienumerable< type_t > & other) -> void
inlineoverridevirtualnoexcept

Modifies the current set so that it contains all elements that are present in the current set, in the specified collection, or in both.

Parameters
otherThe collection to compare to the current set.
Remarks
Any duplicate elements in other are ignored.

Implements xtd::collections::generic::iset< type_t >.


The documentation for this class was generated from the following file: