public int CompareTo(SET <TKey> that) { var union = Union(that); if (_set.Size() == that.Size() && _set.Size() == union.Size() && that.Size() == union.Size()) { return(0); } if (_set.Size() < that.Size()) { return(-1); } return(1); }
/// <summary> /// Returns the intersection of this set and that set. /// </summary> /// <param name="that">that the other set</param> /// <returns>the intersection of this set and that set</returns> /// <exception cref="NullReferenceException">if <tt>that</tt> is <tt>null</tt></exception> public SET <TKey> Intersects(SET <TKey> that) { if (that == null) { throw new NullReferenceException("called intersects() with a null argument"); } var c = new SET <TKey>(); if (Size() < that.Size()) { foreach (var x in this) { if (that.Contains(x)) { c.Add(x); } } } else { foreach (var x in that) { if (this.Contains(x)) { c.Add(x); } } } return(c); }