public InvertibleSet <T> Intersect(InvertibleSet <T> other, bool subtractOther) { bool otherInverted = other._inverted ^ subtractOther; // The result is inverted iff both inputs are inverted. // if both sets are inverted, the base sets should be unioned. // if only one set is inverted, the base set of the inverted one // should be subtracted from the set that is not inverted. if (_inverted || otherInverted) { if (_inverted) { if (otherInverted) { return(new InvertibleSet <T>(_set.Union(other._set), true)); } else { return(new InvertibleSet <T>(other._set.Except(_set), false)); } } else { return(new InvertibleSet <T>(_set.Except(other._set), false)); } } return(new InvertibleSet <T>(_set.Intersect(other._set), false)); }
public InvertibleSet <T> Union(InvertibleSet <T> other) { // if either set is inverted, the result must be inverted. // if both sets are inverted, the base sets should be intersected. // if only one set is inverted, the other set must be subtracted from it. if (_inverted || other._inverted) { if (_inverted) { if (other._inverted) { return(new InvertibleSet <T>(_set.Intersect(other._set), true)); } else { return(new InvertibleSet <T>(_set.Except(other._set), true)); } } else { return(new InvertibleSet <T>(other._set.Except(_set), true)); } } return(new InvertibleSet <T>(_set.Union(other._set), false)); }
public void RegressionTests() { var a = new InvertibleSet <int>(new[] { 1, 2 }, false); var b = new InvertibleSet <int>(new[] { 1, 2, 3 }, true); var c = new InvertibleSet <int>(new[] { 3 }, true); That(!b.SetEquals(c)); That(b.Union(a).SetEquals(c)); That(a.Union(b).SetEquals(c)); // bug fix: this one failed }
public bool SetEquals(InvertibleSet <T> other) { return(_inverted == other._inverted && _set.SetEquals(other._set)); }
/// <inheritdoc cref="InternalSet{T}.IsProperSupersetOf(ISet{T}, IEqualityComparer{T}, int)"/> public bool IsProperSupersetOf(InvertibleSet <T> other) { throw new NotImplementedException(); }
/// <summary>Returns true if this set contains at least one item from 'other'.</summary> public bool Overlaps(InvertibleSet <T> other) { throw new NotImplementedException(); }
bool IEquatable <InvertibleSet <T> > .Equals(InvertibleSet <T> other) { return(SetEquals(other)); }
public InvertibleSet <T> Xor(InvertibleSet <T> other) { return(new InvertibleSet <T>(_set.Xor(other._set), _inverted ^ other._inverted)); }
public InvertibleSet <T> Except(InvertibleSet <T> other) { // Subtraction is equivalent to intersection with the inverted set. return(Intersect(other, true)); }
public InvertibleSet <T> Intersect(InvertibleSet <T> other) { return(Intersect(other, false)); }