/// <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); }
/// <summary> /// Builds the union 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> BitwiseOr(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(BitwiseOr(set2, set1)); } IndexedSet <T> result = new IndexedSet <T>(); result.AddRange(set2); foreach (T item in set1) { if (set2.Contains(item)) { continue; } result.Add(item); } return(result); }