public EasySet <T> Intersection(EasySet <T> easySet) { //return new EasySet<T>(items.Intersect(easySet.items)); var result = new EasySet <T>(); EasySet <T> big; EasySet <T> small; if (Count >= easySet.Count) { big = this; small = easySet; } else { big = easySet; small = this; } foreach (var item1 in small.items) { foreach (var item2 in big.items) { if (item1.Equals(item2)) { result.Add(item1); break; } } } return(result); }
public bool Subset(EasySet <T> easySet) { //return items.All(i => easySet.items.Contains(i)); foreach (var item1 in items) { var equals = false; foreach (var item2 in easySet.items) { if (item1.Equals(item2)) { equals = true; break; } } if (!equals) { return(false); } } return(true); }
public EasySet <T> Difference(EasySet <T> easySet) { //return new EasySet<T>(items.Except(easySet.items)); var result = new EasySet <T>(items); foreach (var item in easySet.items) { result.Remove(item); } return(result); }
public EasySet <T> SymmetricDifference(EasySet <T> easySet) { //return new EasySet<T>(items.Except(easySet.items).Union(easySet.items.Except(items))); var result = new EasySet <T>(); foreach (var item1 in items) { var equals = false; foreach (var item2 in easySet.items) { if (item1.Equals(item2)) { equals = true; break; } } if (!equals) { result.Add(item1); } } foreach (var item1 in easySet.items) { var equals = false; foreach (var item2 in items) { if (item1.Equals(item2)) { equals = true; break; } } if (!equals) { result.Add(item1); } } return(result); }
public EasySet <T> Union(EasySet <T> easySet) { //return new EasySet<T>(items.Union(easySet.items)); EasySet <T> result = new EasySet <T>(); foreach (var item in items) { result.Add(item); } foreach (var item in easySet.items) { result.Add(item); } return(result); }