Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
 public bool Overlaps(SortedMultiset <T> other)
 {
     return(_backingDict.Keys.Any(other._backingDict.ContainsKey));
 }
Esempio n. 7
0
 public bool IsProperSubsetOf(SortedMultiset <T> other)
 {
     return(IsSubsetOf(other) && !SetEquals(other));
 }
Esempio n. 8
0
 public bool IsSupersetOf(SortedMultiset <T> other)
 {
     // subset and superset are opposite
     return(other.IsSubsetOf(this));
 }