@@ -16,34 +16,16 @@ public EnumBitSet() {}
16
16
17
17
public EnumBitSet ( T value )
18
18
{
19
- _data = GetBitMask ( value ) ;
19
+ _data = _data . GetBitMask ( value ) ;
20
20
}
21
21
22
22
public EnumBitSet ( IEnumerable < T > values )
23
23
{
24
- _data = GetBitMask ( values ) ;
24
+ _data = _data . GetBitMask ( values ) ;
25
25
}
26
26
27
27
public EnumBitSet ( params T [ ] values ) : this ( ( IEnumerable < T > ) values ) { }
28
28
29
- public bool this [ T index ]
30
- {
31
- get => this [ GetBitMask ( index ) ] ;
32
- set => this [ GetBitMask ( index ) ] = value ;
33
- }
34
-
35
- public bool this [ IEnumerable < T > index ]
36
- {
37
- get => this [ GetBitMask ( index ) ] ;
38
- set => this [ GetBitMask ( index ) ] = value ;
39
- }
40
-
41
- public bool this [ params T [ ] indices ]
42
- {
43
- get => this [ ( IEnumerable < T > ) indices ] ;
44
- set => this [ ( IEnumerable < T > ) indices ] = value ;
45
- }
46
-
47
29
public bool Any ( )
48
30
{
49
31
return _data . HaveSetBits ( ) ;
@@ -53,60 +35,52 @@ public bool Any()
53
35
54
36
public void ExceptWith ( IEnumerable < T > other )
55
37
{
56
- this [ other ] = false ;
38
+ _data = _data . Difference ( other ) ;
57
39
}
58
40
59
41
public void IntersectWith ( IEnumerable < T > other )
60
42
{
61
- var mask = GetBitMask ( other ) ;
62
- _data = _data . BitAnd ( mask ) ;
43
+ _data = _data . Intersection ( other ) ;
63
44
}
64
45
65
46
public bool IsProperSubsetOf ( IEnumerable < T > other )
66
47
{
67
- var mask = GetBitMask ( other ) ;
68
- return _data . BitAnd ( mask ) . Equals ( _data ) && mask . BitAnd ( _data . BitNot ( ) ) . HaveSetBits ( ) ;
48
+ return _data . IsProperSubsetOf ( other ) ;
69
49
}
70
50
71
51
public bool IsProperSupersetOf ( IEnumerable < T > other )
72
52
{
73
- var mask = GetBitMask ( other ) ;
74
- return mask . BitAnd ( _data ) . Equals ( mask ) && _data . BitAnd ( mask . BitNot ( ) ) . HaveSetBits ( ) ;
53
+ return _data . IsProperSupersetOf ( other ) ;
75
54
}
76
55
77
56
public bool IsSubsetOf ( IEnumerable < T > other )
78
57
{
79
- var mask = GetBitMask ( other ) ;
80
- return _data . BitAnd ( mask ) . Equals ( _data ) ;
58
+ return _data . IsSubsetOf ( other ) ;
81
59
}
82
60
83
61
public bool IsSupersetOf ( IEnumerable < T > other )
84
62
{
85
- var mask = GetBitMask ( other ) ;
86
- return mask . BitAnd ( _data ) . Equals ( mask ) ;
63
+ return _data . IsSupersetOf ( other ) ;
87
64
}
88
65
89
66
public bool Overlaps ( IEnumerable < T > other )
90
67
{
91
- var mask = GetBitMask ( other ) ;
92
- return _data . BitAnd ( mask ) . HaveSetBits ( ) ;
68
+ return _data . Overlaps ( other ) ;
93
69
}
94
70
95
71
public bool SetEquals ( IEnumerable < T > other )
96
72
{
97
- var mask = GetBitMask ( other ) ;
98
- return _data . Equals ( mask ) ;
73
+ return _data . SetEquals ( other ) ;
99
74
}
100
75
101
76
public void SymmetricExceptWith ( IEnumerable < T > other )
102
77
{
103
- var mask = GetBitMask ( other ) ;
104
- _data = _data . BitXor ( mask ) ;
78
+ _data = _data . SymmetricDifference ( other ) ;
105
79
}
106
80
107
81
public void UnionWith ( IEnumerable < T > other )
108
82
{
109
- this [ other ] = true ;
83
+ _data = _data . Union ( other ) ;
110
84
}
111
85
112
86
#endregion
@@ -115,16 +89,16 @@ public void UnionWith(IEnumerable<T> other)
115
89
116
90
void ICollection < T > . Add ( T item )
117
91
{
118
- this [ item ] = true ;
92
+ _data = _data . Union ( item ) ;
119
93
}
120
94
121
95
public bool Add ( T item )
122
96
{
123
- if ( this [ item ] )
97
+ if ( _data . Contains ( item ) )
124
98
{
125
99
return false ;
126
100
}
127
- this [ item ] = true ;
101
+ _data = _data . Union ( item ) ;
128
102
return true ;
129
103
}
130
104
@@ -135,7 +109,7 @@ public void Clear()
135
109
136
110
public bool Contains ( T item )
137
111
{
138
- return this [ item ] ;
112
+ return _data . Contains ( item ) ;
139
113
}
140
114
141
115
public void CopyTo ( T [ ] array , int arrayIndex )
@@ -163,11 +137,11 @@ public void CopyTo(T[] array, int arrayIndex)
163
137
164
138
public bool Remove ( T item )
165
139
{
166
- if ( ! this [ item ] )
140
+ if ( ! _data . Contains ( item ) )
167
141
{
168
142
return false ;
169
143
}
170
- this [ item ] = false ;
144
+ _data = _data . Difference ( item ) ;
171
145
return true ;
172
146
}
173
147
@@ -190,34 +164,5 @@ IEnumerator IEnumerable.GetEnumerator()
190
164
}
191
165
192
166
#endregion
193
-
194
- private bool this [ TData mask ]
195
- {
196
- get => mask . HaveSetBits ( ) && _data . BitAnd ( mask ) . Equals ( mask ) ;
197
- set => _data = value ? _data . BitOr ( mask ) : _data . BitAnd ( mask . BitNot ( ) ) ;
198
- }
199
-
200
- private TData GetBitMask ( T value )
201
- {
202
- return _data . GetBitMask ( value ) ;
203
- }
204
-
205
- private TData GetBitMask ( IEnumerable < T > other )
206
- {
207
- switch ( other )
208
- {
209
- case TData data :
210
- return data ;
211
-
212
- case EnumBitSet < T , TData > bitset :
213
- return bitset . _data ;
214
-
215
- case null :
216
- throw new ArgumentNullException ( nameof ( other ) , "Value cannot be null." ) ;
217
-
218
- default :
219
- return _data . GetBitMask ( other ) ;
220
- }
221
- }
222
167
}
223
168
}
0 commit comments