Exemple #1
0
        public IStrictSet <T> Intersect(IStrictSet <T> other)
        {
            other.ValidateNotNull("The set is null!");
            var itemArray = new T[Count];
            var index     = 0;

            foreach (var item in Items)
            {
                if (!other.Contains(item))
                {
                    itemArray[index++] = item;
                }
            }

            foreach (var item in itemArray)
            {
                if (item == null)
                {
                    break;
                }
                Remove(item);
            }

            return(this);
        }
Exemple #2
0
 private void Fill(IStrictSet <int> set, int start, int count)
 {
     foreach (var i in Enumerable.Range(start, count))
     {
         set.Add(i);
     }
 }
Exemple #3
0
        public IStrictSet <T> Differ(IStrictSet <T> other)
        {
            other.ValidateNotNull("The set is null!");
            foreach (var item in other)
            {
                if (Contains(item))
                {
                    Remove(item);
                }
            }

            return(this);
        }
Exemple #4
0
        public IStrictSet <T> Union(IStrictSet <T> other)
        {
            other.ValidateNotNull("The set is null!");
            foreach (var item in other)
            {
                if (!Contains(item))
                {
                    Add(item);
                }
            }

            return(this);
        }
Exemple #5
0
        public bool IsSubsetOf(IStrictSet <T> other)
        {
            other.ValidateNotNull("The set is null!");
            var isSubset = true;

            foreach (var item in Items)
            {
                if (!other.Contains(item))
                {
                    isSubset = false;
                    break;
                }
            }

            return(isSubset);
        }
Exemple #6
0
        public bool IsDisjointWith(IStrictSet <T> other)
        {
            other.ValidateNotNull("The set is null!");
            var disjoint = true;

            foreach (var item in other)
            {
                if (Contains(item))
                {
                    disjoint = false;
                    break;
                }
            }

            return(disjoint);
        }
Exemple #7
0
        public IStrictSet <T> Compliment(IStrictSet <T> universe)
        {
            if (!IsSubsetOf(universe))
            {
                throw new InvalidOperationException("Cannot calculate the compliment, as the current set is not the subset of the universe set.");
            }
            foreach (var item in universe)
            {
                if (Contains(item))
                {
                    Remove(item);
                }
                else
                {
                    Add(item);
                }
            }

            return(this);
        }
Exemple #8
0
        public bool IsProperSubsetOf(IStrictSet <T> other)
        {
            var isSubset = IsSubsetOf(other);

            return(isSubset && other.Count > Count);
        }
Exemple #9
0
 public bool IsEqualWith(IStrictSet <T> other)
 {
     other.ValidateNotNull("the set is null!");
     return(other.IsSubsetOf(this) && IsSubsetOf(other));
 }