public void SymmetricExceptWith(IEnumerable <T> other) { CountingSet <T> newSet = new CountingSet <T>(elements); CountingSet <T> intersection = new CountingSet <T>(elements); intersection.IntersectWith(other); newSet.UnionWith(other); newSet.ExceptWith(intersection); elements = newSet.elements; count = newSet.count; }
public bool SetEquals(IEnumerable <T> other) { CountingSet <T> set = new CountingSet <T>(other); foreach (var pair in elements) { if (set.Get(pair.item) != pair.count) { return(false); } } return(true); }
public bool IsSubsetOf(IEnumerable <T> other) { CountingSet <T> set = new CountingSet <T>(other); foreach (var pair in elements) { for (int i = 0; i < pair.count; i++) { if (!set.Remove(pair.item)) { return(false); } } } return(true); }
public void UnionWith(IEnumerable <T> other) { CountingSet <T> set = new CountingSet <T>(other); foreach (var pair in set.elements) { int newCount = Math.Max(count, this[pair.item]); if (TryGet(pair.item, out CountingPair <T> myPair)) { myPair.count = newCount; } else { elements.Add(new CountingPair <T> { item = pair.item, count = pair.count }); } } }
public void IntersectWith(IEnumerable <T> other) { CountingSet <T> newSet = new CountingSet <T>(); foreach (T item in other) { int count = 1; if (other is CountingSet <T> set) { count = set[item]; } int newCount = Math.Min(count, this[item]); for (int i = 0; i < newCount; i++) { newSet.Add(item); } } elements = newSet.elements; count = newSet.count; }
public bool IsSupersetOf(IEnumerable <T> other) { CountingSet <T> set = new CountingSet <T>(other); return(set.IsProperSupersetOf(this)); }