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
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:45
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
- 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() {
for (
auto i = 0;
i < 5; ++
i) {
even_numbers.add(i * 2);
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);
auto numbers = even_numbers;
numbers.union_with(odd_numbers);
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(" }");
}
};
}
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:284
@ i
The I key.
Definition console_key.hpp:104
|
| 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_type > | get_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.
|
|
| 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 | 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.
|
| 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 | 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 | 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 (xtd::size 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 | count () const noexcept -> xtd::size |
| | Returns the number of elements in current sequence.
|
| 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 | 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 | distinct () const noexcept |
| | Returns distinct elements from a sequence by using the default equality comparer 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 | order () const |
| | 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_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 | select (const std::function< result_t(const type_t &)> &selector) const |
| | Projects each element of a sequence into a new form.
|
| 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 -> xtd::collections::generic::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.
|
| 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_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.
|