/// <summary> /// Симметричная разность /// </summary> public HashTableSet <T> SymmetricDifference(HashTableSet <T> set) { var temp = Intersection(set); var tempUnion = Union(set); return(tempUnion.Difference(temp)); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }