public bool SetEquals(SortedMultiset <T> other) { foreach (var myItem in _backingDict) { if (!other._backingDict.ContainsKey(myItem.Key) || other._backingDict[myItem.Key] != myItem.Value) { return(false); } } return(true); }
public bool IsSubsetOf(SortedMultiset <T> other) { foreach (var myItem in _backingDict) { // if the other set doesn't contain each of my items or contains less of one of the items, it's not a subset if (!other._backingDict.ContainsKey(myItem.Key) || other._backingDict[myItem.Key] < myItem.Value) { return(false); } } return(true); }
public void SymmetricExceptWith(IEnumerable <T> other) { // a symdiff b = (a union b) setminus (a intersect b) var union = new SortedMultiset <T>(this); union.UnionWith(other); var intersection = new SortedMultiset <T>(this); intersection.IntersectWith(other); union.ExceptWith(intersection); _backingDict = union._backingDict; }
public void IntersectWith(SortedMultiset <T> other) { var newBackingDict = new SortedDictionary <T, int>(); foreach (var item in _backingDict) { if (other._backingDict.ContainsKey(item.Key)) { int myCount = item.Value; int theirCount = other._backingDict[item.Key]; newBackingDict[item.Key] = Math.Min(myCount, theirCount); } } _backingDict = newBackingDict; }
public void ExceptWith(SortedMultiset <T> other) { var newBackingDict = new SortedDictionary <T, int>(); foreach (var item in _backingDict) { if (other._backingDict.ContainsKey(item.Key)) { int myCount = item.Value; int theirCount = other._backingDict[item.Key]; if (myCount - theirCount <= 0) { // don't add this item at all continue; } newBackingDict[item.Key] = myCount - theirCount; } } _backingDict = newBackingDict; }
public bool Overlaps(SortedMultiset <T> other) { return(_backingDict.Keys.Any(other._backingDict.ContainsKey)); }
public bool IsProperSubsetOf(SortedMultiset <T> other) { return(IsSubsetOf(other) && !SetEquals(other)); }
public bool IsSupersetOf(SortedMultiset <T> other) { // subset and superset are opposite return(other.IsSubsetOf(this)); }