//----------------------------- Static Methods --------------------------------- // Functional Intersect public static GSet <T> /*!*/ Intersect(GSet <T> /*!*/ a, GSet <T> /*!*/ b) { Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result <GSet <T> >() != null); //Contract.Ensures(Contract.ForAll(result, x => a[x] && b[x] )); GSet <T> /*!*/ res = (GSet <T> /*!*/)cce.NonNull(a.Clone()); res.Intersect(b); return(res); }
// Functional Union public static GSet <T> /*!*/ Union(GSet <T> /*!*/ a, GSet <T> /*!*/ b) { Contract.Requires(a != null); Contract.Requires(b != null); Contract.Ensures(Contract.Result <GSet <T> >() != null); // Contract.Ensures(Contract.ForAll(result, x => a[x] || b[x] )); GSet <T> /*!*/ res = (GSet <T> /*!*/)cce.NonNull(a.Clone()); res.AddRange(b); return(res); }
public static GSet <T> /*!*/ Filter(GSet <T> /*!*/ a, Func <T, bool> filter) { Contract.Requires(filter != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result <GSet <T> >() != null); GSet <T> inter = new GSet <T>(); foreach (T elem in a) { Contract.Assert(elem != null); if (filter(elem)) { inter.Add(elem); } } return(inter); }
public void Intersect(GSet <T> /*!*/ s) { Contract.Requires(s != null); if (s == this) { return; } ht.Clear(); var newArr = new List <T>(); foreach (T key in arr) { if (s.ht.ContainsKey(key)) { ht[key] = newArr.Count; newArr.Add(key); } } arr = newArr; }