예제 #1
0
        /// <summary>
        /// Симметричная разность
        /// </summary>
        public HashTableSet <T> SymmetricDifference(HashTableSet <T> set)
        {
            var temp      = Intersection(set);
            var tempUnion = Union(set);

            return(tempUnion.Difference(temp));
        }
예제 #2
0
 /// <summary>
 /// Содержит ли множество заданное подмножество
 /// </summary>
 public bool IsSubset(HashTableSet <T> set)
 {
     for (int i = 0; i < set.Count; i++)
     {
         var list = set.items.GetItem(i);
         foreach (var item in list)
         {
             if (!items.Search(item))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #3
0
        /// <summary>
        /// Разность множеств
        /// </summary>
        /// <returns></returns>
        public HashTableSet <T> Difference(HashTableSet <T> set)
        {
            int resSize             = Count;
            HashTableSet <T> result = new HashTableSet <T>(resSize);

            for (int i = 0; i < Count; i++)
            {
                var list = items.GetItem(i);
                foreach (var item in list)
                {
                    if (!set.items.Search(item))
                    {
                        result.Add(item);
                    }
                }
            }
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Пересечение множеств
        /// </summary>
        /// <returns></returns>
        public HashTableSet <T> Intersection(HashTableSet <T> set)
        {
            int resSize             = (Count >= set.Count) ? Count : set.Count;
            HashTableSet <T> result = new HashTableSet <T>(resSize);

            for (int i = 0; i < Count; i++)
            {
                var list = items.GetItem(i);
                foreach (var item in list)
                {
                    if (set.items.Search(item))
                    {
                        result.Add(item);
                    }
                }
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// Объединение множеств
        /// </summary>
        /// <returns></returns>
        public HashTableSet <T> Union(HashTableSet <T> set)
        {
            int resSize             = Count + set.Count;
            HashTableSet <T> result = new HashTableSet <T>(resSize);

            for (int i = 0; i < Count; i++)
            {
                var list = items.GetItem(i);
                foreach (var item in list)
                {
                    result.Add(item);
                }
            }
            for (int i = 0; i < set.Count; i++)
            {
                var list = set.items.GetItem(i);
                foreach (var item in list)
                {
                    result.Add(item);
                }
            }
            return(result);
        }