Пример #1
0
        public GenericSet <T> Union(GenericSet <T> other)
        {
            GenericSet <T> newSet = new GenericSet <T>();

            newSet.AddItemsFromSet(this);
            newSet.AddItemsFromSet(other);

            return(newSet);
        }
Пример #2
0
        public bool IsSubset(GenericSet <T> other)
        {
            if (other.IsNull())
            {
                throw new ArgumentNullException("other");
            }

            if (this.Size > other.Size)
            {
                return(false);
            }
            return(data.Keys.All(item => other.Contains(item)));
        }
Пример #3
0
 private void AddItemsFromSet(GenericSet <T> other)
 {
     if (other.IsNotNull())
     {
         foreach (T item in other.data.Keys)
         {
             if (!Contains(item))
             {
                 Add(item);
             }
         }
     }
 }
Пример #4
0
        public override bool Equals(object obj)
        {
            if (obj.IsNull())
            {
                return(false);
            }

            if (GetType() != obj.GetType())
            {
                return(false);
            }

            GenericSet <T> other = obj as GenericSet <T>;

            return(this.IsSubset(other) && other.IsSubset(this));
        }
Пример #5
0
        public GenericSet <T> Difference(GenericSet <T> other)
        {
            if (other.IsNull())
            {
                throw new ArgumentNullException("other");
            }

            GenericSet <T> newSet = new GenericSet <T>();

            foreach (T item in data.Keys)
            {
                if (!other.Contains(item))
                {
                    newSet.Add(item);
                }
            }

            return(newSet);
        }
Пример #6
0
        public GenericSet <T> Intersection(GenericSet <T> other)
        {
            GenericSet <T> newSet = new GenericSet <T>();

            if (other.IsNull())
            {
                return(null);
            }

            foreach (T key in data.Keys)
            {
                if (other.Contains(key))
                {
                    newSet.Add(key);
                }
            }

            return(newSet);
        }