public GenericSet <T> Union(GenericSet <T> other) { GenericSet <T> newSet = new GenericSet <T>(); newSet.AddItemsFromSet(this); newSet.AddItemsFromSet(other); return(newSet); }
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))); }
private void AddItemsFromSet(GenericSet <T> other) { if (other.IsNotNull()) { foreach (T item in other.data.Keys) { if (!Contains(item)) { Add(item); } } } }
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)); }
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); }
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); }