/// <summary> /// intersection of two sets. /// </summary> /// <param name="set"></param> /// <returns></returns> public EasySet <T> Intersection(EasySet <T> set) { return(new EasySet <T>(items.Intersect(set.items))); //var result = new EasySet<T>(); //EasySet<T> big; //EasySet<T> small; //if (count > set.count) //{ // big = this; // small = set; //} //else //{ // big = set; // small = this; //} //foreach (var item1 in small.items) //{ // foreach (var item2 in big.items) // { // if (item1.Equals(item2)) // { // result.Add(item1); // break; // } // } //} //return result; }
/// <summary> /// Difference of two sets. /// </summary> /// <param name="set"></param> /// <returns></returns> public EasySet <T> Difference(EasySet <T> set) { //return new EasySet<T>(items.Except(set.items)); var result = new EasySet <T>(items); foreach (var item in set.items) { result.Remove(item); } return(result); }
/// <summary> /// Union of two sets. /// </summary> /// <param name="set"></param> /// <returns></returns> public EasySet <T> Union(EasySet <T> set) { return(new EasySet <T>(items.Union(set.items))); //EasySet<T> result = new EasySet<T>(); //foreach (var item in items) //{ // result.Add(item); //} //foreach (var item in set.items) //{ // result.Add(item); //} //return result; }
/// <summary> /// Subset for two set. /// </summary> /// <param name="set"></param> /// <returns></returns> public bool Subset(EasySet <T> set) { return(items.All(i => set.items.Contains(i))); //foreach (var item1 in items) //{ // var equals = false; // foreach (var item2 in set.items) // { // if(item1.Equals(item2)) // { // equals = true; // break; // } // } // if(!equals) // { // return false; // } //} //return true; }
public EasySet <T> SymetricDifference(EasySet <T> set) { return(new EasySet <T>(items.Except(set.items).Union(set.items.Except(items)))); //var result = new EasySet<T>(); //foreach (var item1 in set.items) //{ // var equals = false; // foreach (var item2 in items) // { // if(item1.Equals(item2)) // { // equals = true; // break; // } // } // if(!equals) // { // result.Add(item1); // } //} //foreach (var item1 in items) //{ // var equals = false; // foreach (var item2 in set.items) // { // if (item1.Equals(item2)) // { // equals = true; // break; // } // } // if (!equals) // { // result.Add(item1); // } //} //return result; }