Enhanced C#
Language of your choice: library documentation
|
An immutable set that can be inverted. For example, an InvertibleSet<int>
could contain "everything except 4 and 10", or it could contain a positive set such as "1, 2, and 3".
More...
An immutable set that can be inverted. For example, an InvertibleSet<int>
could contain "everything except 4 and 10", or it could contain a positive set such as "1, 2, and 3".
InvertibleSet
is implemented as a normal Set<T> plus an IsInverted flag. The original (non-inverted) set can be retrieved from the BaseSet property
Note: this class is designed with the assumption that there are an infinite number of possible T objects, and under certain conditions the set-testing operations such as Equals() and IsSubsetOf() can return false when they should return true. For example, consider two sets of bytes: one set holds the numbers 0..100, and the other contains 101..255 but is marked as inverted. Arguably, Equals() and IsSubsetOf() should return true when comparing these sets, but they return false because they are unaware of the finite nature of a byte.
Performance warning: GetHashCode() XORs the hashcodes of all items in the set, while Equals() is a synonym for SetEquals(). Be aware that these methods are very slow for large sets.
Public static fields | |
static readonly InvertibleSet< T > | Empty = new InvertibleSet<T>(Set<T>.Empty, false) |
static readonly InvertibleSet< T > | All = new InvertibleSet<T>(Set<T>.Empty, true) |
Properties | |
Set< T > | BaseSet [get] |
bool | IsInverted [get] |
bool | IsEmpty [get] |
bool | ContainsEverything [get] |
Public Member Functions | |
InvertibleSet (Set< T > set, bool inverted) | |
InvertibleSet (IEnumerable< T > list, bool inverted=false) | |
InvertibleSet (IEnumerable< T > list, IEqualityComparer< T > comparer, bool inverted=false) | |
InvertibleSet< T > | Inverted () |
bool | Contains (T item) |
InvertibleSet< T > | Without (T item) |
InvertibleSet< T > | With (T item) |
InvertibleSet< T > | Union (InvertibleSet< T > other) |
InvertibleSet< T > | Intersect (InvertibleSet< T > other) |
InvertibleSet< T > | Intersect (InvertibleSet< T > other, bool subtractOther) |
InvertibleSet< T > | Except (InvertibleSet< T > other) |
InvertibleSet< T > | Xor (InvertibleSet< T > other) |
override int | GetHashCode () |
override bool | Equals (object obj) |
bool | IsSubsetOf (InvertibleSet< T > other) |
TODO NOT IMPLEMENTED Returns true if all items in this set are present in the other set. More... | |
bool | IsSupersetOf (InvertibleSet< T > other) |
TODO NOT IMPLEMENTED Returns true if all items in the other set are present in this set. More... | |
bool | Overlaps (InvertibleSet< T > other) |
TODO NOT IMPLEMENTED Returns true if this set contains at least one item from 'other'. More... | |
bool | IsProperSubsetOf (InvertibleSet< T > other) |
bool | IsProperSupersetOf (InvertibleSet< T > other) |
bool | SetEquals (InvertibleSet< T > other) |
Static Public Member Functions | |
static InvertibleSet< T > | With (params T[] list) |
static InvertibleSet< T > | Without (params T[] list) |
Protected Member Functions | |
InvertibleSet< T > | With (T item, bool removed) |
|
inline |
TODO NOT IMPLEMENTED Returns true if all items in this set are present in the other set.
|
inline |
TODO NOT IMPLEMENTED Returns true if all items in the other set are present in this set.
|
inline |
TODO NOT IMPLEMENTED Returns true if this set contains at least one item from 'other'.