Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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
                    });
                }
            }
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        public bool IsSupersetOf(IEnumerable <T> other)
        {
            CountingSet <T> set = new CountingSet <T>(other);

            return(set.IsProperSupersetOf(this));
        }