DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
HashSet.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
Common.h
"
4
#include "
System/Object.h
"
5
#include "
System/Array.h
"
6
#include "
System/Collections/Generic/Dictionary.h
"
7
#include <new>
8
#include <initializer_list>
9
#include <utility>
10
11
namespace
DotNetDupe
{
12
namespace
System
{
13
namespace
Collections
{
14
namespace
Generic
{
15
22
template
<
typename
T>
23
class
HashSet
:
public
Object
{
24
private
:
25
Dictionary<T, bool>
m_dict;
26
27
public
:
29
HashSet
() {}
30
32
HashSet
(
const
HashSet
& other) : m_dict(other.m_dict) {}
33
35
HashSet
(
HashSet
&& other) noexcept : m_dict(std::move(other.m_dict)) {}
36
38
HashSet
&
operator=
(
const
HashSet
& other) {
39
if
(
this
!= &other) {
40
m_dict = other.m_dict;
41
}
42
return
*
this
;
43
}
44
46
HashSet
&
operator=
(
HashSet
&& other)
noexcept
{
47
if
(
this
!= &other) {
48
m_dict = std::move(other.m_dict);
49
}
50
return
*
this
;
51
}
52
54
~HashSet
()
override
{}
55
58
int
GetCount
()
const
{
return
m_dict.GetCount(); }
59
63
bool
Add
(
const
T& item) {
64
if
(m_dict.ContainsKey(item))
return
false
;
65
m_dict.Add(item,
true
);
66
return
true
;
67
}
68
72
bool
Remove
(
const
T& item) {
73
return
m_dict.Remove(item);
74
}
75
79
bool
Contains
(
const
T& item)
const
{
80
return
m_dict.ContainsKey(item);
81
}
82
84
void
Clear
() {
85
m_dict.Clear();
86
}
87
90
void
UnionWith
(
const
HashSet<T>
& other) {
91
Array<T>
keys = other.m_dict.
GetKeys
();
92
for
(
int
i = 0; i < keys.
GetLength
(); ++i) {
93
Add
(keys[i]);
94
}
95
}
96
99
void
IntersectWith
(
const
HashSet<T>
& other) {
100
Array<T>
keys = m_dict.GetKeys();
101
for
(
int
i = keys.
GetLength
() - 1; i >= 0; --i) {
102
if
(!other.
Contains
(keys[i])) {
103
Remove
(keys[i]);
104
}
105
}
106
}
107
110
void
ExceptWith
(
const
HashSet<T>
& other) {
111
Array<T>
keys = other.m_dict.
GetKeys
();
112
for
(
int
i = 0; i < keys.
GetLength
(); ++i) {
113
Remove
(keys[i]);
114
}
115
}
116
119
Array<T>
ToArray
()
const
{
120
return
m_dict.GetKeys();
121
}
122
};
123
124
}
125
}
126
}
127
}
Array.h
Provides methods for creating, manipulating, searching, and sorting arrays.
Common.h
Defines common cross-platform macros, export decorators, and fundamental types.
Dictionary.h
Object.h
Base object class for DotNetDupe mirroring .NET System.Object.
DotNetDupe::System::Array
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition
Array.h:29
DotNetDupe::System::Array::GetLength
int GetLength() const
Gets the total number of elements in all dimensions of the Array.
Definition
Array.h:142
DotNetDupe::System::Collections::Generic::Dictionary
Represents a collection of keys and values.
Definition
Dictionary.h:66
DotNetDupe::System::Collections::Generic::Dictionary::GetKeys
Array< TKey > GetKeys() const
Definition
Dictionary.h:307
DotNetDupe::System::Collections::Generic::HashSet::GetCount
int GetCount() const
Gets the number of elements that are contained in a set.
Definition
HashSet.h:58
DotNetDupe::System::Collections::Generic::HashSet::UnionWith
void UnionWith(const HashSet< T > &other)
Modifies the current HashSet object to contain all elements that are present in itself,...
Definition
HashSet.h:90
DotNetDupe::System::Collections::Generic::HashSet::Clear
void Clear()
Removes all elements from a HashSet object.
Definition
HashSet.h:84
DotNetDupe::System::Collections::Generic::HashSet::HashSet
HashSet()
Initializes a new instance of the HashSet class that is empty.
Definition
HashSet.h:29
DotNetDupe::System::Collections::Generic::HashSet::operator=
HashSet & operator=(HashSet &&other) noexcept
Move assignment operator.
Definition
HashSet.h:46
DotNetDupe::System::Collections::Generic::HashSet::~HashSet
~HashSet() override
Destructor.
Definition
HashSet.h:54
DotNetDupe::System::Collections::Generic::HashSet::HashSet
HashSet(HashSet &&other) noexcept
Move constructor.
Definition
HashSet.h:35
DotNetDupe::System::Collections::Generic::HashSet::Add
bool Add(const T &item)
Adds the specified element to a set.
Definition
HashSet.h:63
DotNetDupe::System::Collections::Generic::HashSet::Remove
bool Remove(const T &item)
Removes the specified element from a HashSet object.
Definition
HashSet.h:72
DotNetDupe::System::Collections::Generic::HashSet::ExceptWith
void ExceptWith(const HashSet< T > &other)
Removes all elements in the specified collection from the current HashSet object.
Definition
HashSet.h:110
DotNetDupe::System::Collections::Generic::HashSet::ToArray
Array< T > ToArray() const
Copies the elements of a HashSet object to an Array.
Definition
HashSet.h:119
DotNetDupe::System::Collections::Generic::HashSet::HashSet
HashSet(const HashSet &other)
Copy constructor.
Definition
HashSet.h:32
DotNetDupe::System::Collections::Generic::HashSet::IntersectWith
void IntersectWith(const HashSet< T > &other)
Modifies the current HashSet object to contain only elements that are present in that object and in t...
Definition
HashSet.h:99
DotNetDupe::System::Collections::Generic::HashSet::operator=
HashSet & operator=(const HashSet &other)
Copy assignment operator.
Definition
HashSet.h:38
DotNetDupe::System::Collections::Generic::HashSet::Contains
bool Contains(const T &item) const
Determines whether a HashSet object contains the specified element.
Definition
HashSet.h:79
DotNetDupe::System::Object
Supports all classes in the DotNetDupe class hierarchy.
Definition
Object.h:18
DotNetDupe::System::Collections::Generic
Definition
Dictionary.h:15
DotNetDupe::System::Collections
Definition
BlockingCollection.h:15
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
Include
System
Collections
Generic
HashSet.h
Generated by
1.18.0