コード例 #1
0
        /// <summary>
        /// Builds a new <see cref="Set{T}"/> containing only items found exclusivly in one of both specified sets.
        /// </summary>
        /// <param name="set1">The first set used to calculate the result.</param>
        /// <param name="set2">The second set used to calculate the result.</param>
        /// <returns>Returns a new <see cref="Set{T}"/> containing the result.</returns>
        public static IndexedSet <T> Xor(IndexedSet <T> set1, IndexedSet <T> set2)
        {
            if (set1 == null)
            {
                throw new ArgumentNullException("set1");
            }

            if (set2 == null)
            {
                throw new ArgumentNullException("set2");
            }

            if (set1.Count < set2.Count)
            {
                return(Xor(set2, set1));
            }

            LinkedList <T> newSet2 = new LinkedList <T>(set2);
            IndexedSet <T> result  = new IndexedSet <T>();

            foreach (T setItem in set1)
            {
                if (!set2.Contains(setItem))
                {
                    result.Add(setItem);
                }
                else
                {
                    newSet2.Remove(setItem);
                }
            }
            result.AddRange(newSet2);
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Builds the intersection of two specified <see cref="Set{T}"/>s.
        /// </summary>
        /// <param name="set1">The first set used to calculate the result.</param>
        /// <param name="set2">The second set used to calculate the result.</param>
        /// <returns>Returns a new <see cref="Set{T}"/> containing the result.</returns>
        public static IndexedSet <T> BitwiseAnd(IndexedSet <T> set1, IndexedSet <T> set2)
        {
            if (set1 == null)
            {
                throw new ArgumentNullException("set1");
            }

            if (set2 == null)
            {
                throw new ArgumentNullException("set2");
            }

            if (set1.Count < set2.Count)
            {
                return(BitwiseAnd(set2, set1));
            }

            IndexedSet <T> result = new IndexedSet <T>();

            foreach (T itemsItem in set1)
            {
                if (set2.Contains(itemsItem))
                {
                    result.Add(itemsItem);
                }
            }
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Subtracts the specified <see cref="Set{T}"/> from this one and returns a new <see cref="Set{T}"/> containing the result.
        /// </summary>
        /// <param name="set1">The first set used to calculate the result.</param>
        /// <param name="set2">The second set used to calculate the result.</param>
        /// <returns>Returns a new <see cref="Set{T}"/> containing the result.</returns>
        public static IndexedSet <T> Subtract(IndexedSet <T> set1, IndexedSet <T> set2)
        {
            if (set1 == null)
            {
                throw new ArgumentNullException("set1");
            }

            if (set2 == null)
            {
                throw new ArgumentNullException("set2");
            }

            IndexedSet <T> result = new IndexedSet <T>();

            foreach (T setItem in set1)
            {
                if (!set2.Contains(setItem))
                {
                    result.Add(setItem);
                }
            }
            return(result);
        }
コード例 #4
0
 /// <summary>Checks another Set{T} instance for equality.</summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(IndexedSet <T> other) => (other != null) && (other.Count == Count) && ContainsRange(other);
コード例 #5
0
 /// <summary>
 /// Builds a new <see cref="Set{T}"/> containing only items found exclusivly in one of both specified sets.
 /// </summary>
 /// <param name="items">Provides the other <see cref="Set{T}"/> used.</param>
 /// <returns>Returns a new <see cref="Set{T}"/> containing the result.</returns>
 public IndexedSet <T> ExclusiveOr(IndexedSet <T> items)
 {
     return(Xor(this, items));
 }
コード例 #6
0
 /// <summary>
 /// Subtracts a specified <see cref="Set{T}"/> from this one and returns a new set with the result.
 /// </summary>
 /// <param name="items">Provides the other <see cref="Set{T}"/> used.</param>
 /// <returns>Returns a new <see cref="Set{T}"/> containing the result.</returns>
 public IndexedSet <T> Subtract(IndexedSet <T> items)
 {
     return(Subtract(this, items));
 }
コード例 #7
0
 /// <summary>
 /// Builds the intersection of the specified and this <see cref="Set{T}"/> and returns a new set with the result.
 /// </summary>
 /// <param name="items">Provides the other <see cref="Set{T}"/> used.</param>
 /// <returns>Returns a new <see cref="Set{T}"/> containing the result.</returns>
 public IndexedSet <T> Intersect(IndexedSet <T> items)
 {
     return(BitwiseAnd(this, items));
 }
コード例 #8
0
 /// <summary>
 /// Builds the union of the specified and this <see cref="Set{T}"/> and returns a new set with the result.
 /// </summary>
 /// <param name="items">Provides the other <see cref="Set{T}"/> used.</param>
 /// <returns>Returns a new <see cref="Set{T}"/> containing the result.</returns>
 public IndexedSet <T> Union(IndexedSet <T> items)
 {
     return(BitwiseOr(this, items));
 }