예제 #1
0
        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));
        }
예제 #2
0
 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));
 }
예제 #3
0
        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
        }
예제 #4
0
 public bool SetEquals(InvertibleSet <T> other)
 {
     return(_inverted == other._inverted && _set.SetEquals(other._set));
 }
예제 #5
0
 /// <inheritdoc cref="InternalSet{T}.IsProperSupersetOf(ISet{T}, IEqualityComparer{T}, int)"/>
 public bool IsProperSupersetOf(InvertibleSet <T> other)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 /// <summary>Returns true if this set contains at least one item from 'other'.</summary>
 public bool Overlaps(InvertibleSet <T> other)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 bool IEquatable <InvertibleSet <T> > .Equals(InvertibleSet <T> other)
 {
     return(SetEquals(other));
 }
예제 #8
0
 public InvertibleSet <T> Xor(InvertibleSet <T> other)
 {
     return(new InvertibleSet <T>(_set.Xor(other._set), _inverted ^ other._inverted));
 }
예제 #9
0
 public InvertibleSet <T> Except(InvertibleSet <T> other)
 {
     // Subtraction is equivalent to intersection with the inverted set.
     return(Intersect(other, true));
 }
예제 #10
0
 public InvertibleSet <T> Intersect(InvertibleSet <T> other)
 {
     return(Intersect(other, false));
 }