/// <summary> /// Intersection operation /// </summary> /// <param name="otherSet"></param> /// <returns></returns> public SetUniversal <T> Intersection(SetUniversal <T> otherSet) { //return new SetUniversal<T>(container.Intersect(otherSet)); var result = new SetUniversal <T>(); SetUniversal <T> big; SetUniversal <T> small; if (Count > otherSet.Count) { big = this; small = otherSet; } else { big = otherSet; small = this; } foreach (var item1 in small.container) { foreach (var item2 in big.container) { if (item1.Equals(item2)) { result.Add(item1); } break; } } return(result); }
/// <summary> /// Difference operation /// </summary> /// <param name="otherSet"></param> /// <returns></returns> public SetUniversal <T> Difference(SetUniversal <T> otherSet) { //return new SetUniversal<T>(container.Except(otherSet.container)); var result = new SetUniversal <T>(container); foreach (var item in otherSet.container) { result.Remove(item); } return(result); }
/// <summary> /// Union operation /// </summary> /// <param name="otherSet"></param> /// <returns></returns> public SetUniversal <T> Union(SetUniversal <T> otherSet) { //return new SetUniversal<T>(container.Union(otherSet)); var result = new SetUniversal <T>(); foreach (var item in container) { result.Add(item); } foreach (var item in otherSet.container) { result.Add(item); } return(result); }
/// <summary> /// Subset operation /// </summary> /// <param name="otherSet"></param> /// <returns></returns> public bool Subset(SetUniversal <T> otherSet) { //return otherSet.container.All(i => container.Contains(i)); foreach (var item1 in otherSet.container) { var equals = false; foreach (var item2 in container) { if (item1.Equals(item2)) { equals = true; break; } } if (!equals) { return(false); } } return(true); }