Esempio n. 1
0
        /// <summary>
        /// Returns set of items of first set without items of second set
        /// </summary>
        /// <param name="set1"></param>
        /// <param name="set2"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static CustomSet <T> Except(CustomSet <T> set1, CustomSet <T> set2)
        {
            if (set1 == null || set2 == null)
            {
                throw new ArgumentNullException();
            }
            CustomSet <T> result = new CustomSet <T>(set1);

            for (int i = 0; i < set2.Count; i++)
            {
                result.Remove(set2.Collection[i]);
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns set of items each set contains
        /// </summary>
        /// <param name="set1"></param>
        /// <param name="set2"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static CustomSet <T> Intersect(CustomSet <T> set1, CustomSet <T> set2)
        {
            if (set1 == null || set2 == null)
            {
                throw new ArgumentNullException();
            }
            CustomSet <T> result = new CustomSet <T>();

            for (int i = 0; i < set1.Count; i++)
            {
                if (set1.Collection.Contains(set2.Collection[i]))
                {
                    result.Add(set2.Collection[i]);
                }
            }
            return(result);
        }
Esempio n. 3
0
        bool IEquatable <CustomSet <T> > .Equals(CustomSet <T> other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (Count != other.Count)
            {
                return(false);
            }
            return(!other.Where((t, i) => !Collection.Contains(other.Collection[i])).Any());
            //for (int i = 0; i < other.Count; i++)
            //    if (!Collection.Contains(other.Collection[i]))
            //        return false;
            //return true;
        }
Esempio n. 4
0
 /// <summary>
 /// Creates set from another set
 /// </summary>
 /// <param name="set"></param>
 public CustomSet(CustomSet <T> set)
 {
     Collection = new CustomCollection <T>(set.Collection);
 }