public SetInternal <OrdA, A> Subtract(SetInternal <OrdA, A> rhs) { if (Count == 0) { return(Empty); } if (rhs.Count == 0) { return(this); } if (rhs.Count < Count) { var self = this; foreach (var item in rhs) { self = self.Remove(item); } return(self); } else { var root = SetItem <A> .Empty; foreach (var item in this) { if (!rhs.Contains(item)) { root = SetModuleM.Add <OrdA, A>(root, item, SetModuleM.AddOpt.TryAdd); } } return(new SetInternal <OrdA, A>(root)); } }
public SetInternal <OrdA, A> Subtract(SetInternal <OrdA, A> rhs) { var self = this; foreach (var item in rhs) { self = self.Remove(item); } return(self); }
public SetInternal <OrdA, A> Except(SetInternal <OrdA, A> rhs) { var root = SetItem <A> .Empty; foreach (var item in this) { if (!rhs.Contains(item)) { root = SetModuleM.Add <OrdA, A>(root, item, SetModuleM.AddOpt.TryAdd); } } return(new SetInternal <OrdA, A>(root)); }
public bool SetEquals(IEnumerable <A> other) { var rhs = new SetInternal <OrdA, A>(other); if (rhs.Count != Count) { return(false); } foreach (var item in rhs) { if (!Contains(item)) { return(false); } } return(true); }
public bool IsSubsetOf(IEnumerable <A> other) { if (IsEmpty) { return(true); } var otherSet = new SetInternal <OrdA, A>(other); int matches = 0; foreach (A item in otherSet) { if (Contains(item)) { matches++; } } return(matches == Count); }
public int CompareTo <OrdAlt>(SetInternal <OrdA, A> other) where OrdAlt : struct, Ord <A> { var cmp = Count.CompareTo(other.Count); if (cmp != 0) { return(cmp); } var iterA = GetEnumerator(); var iterB = other.GetEnumerator(); while (iterA.MoveNext() && iterB.MoveNext()) { cmp = default(OrdAlt).Compare(iterA.Current, iterB.Current); if (cmp != 0) { return(cmp); } } return(0); }
public SetInternal <OrdA, A> SymmetricExcept(IEnumerable <A> other) { var rhs = new SetInternal <OrdA, A>(other); var res = new List <A>(); foreach (var item in this) { if (!rhs.Contains(item)) { res.Add(item); } } foreach (var item in other) { if (!Contains(item)) { res.Add(item); } } return(new SetInternal <OrdA, A>(res)); }
public bool Equals(SetInternal <OrdA, A> other) => SetEquals(other.AsEnumerable());
public SetInternal <OrdA, A> Append(SetInternal <OrdA, A> rhs) => Union(rhs.AsEnumerable());
/// <summary> /// Default ctor /// </summary> internal Set(SetInternal <OrdDefault <A>, A> set) =>
/// <summary> /// Default ctor /// </summary> internal Set(SetInternal <OrdA, A> set) =>
/// <summary> /// Ctor from an enumerable /// </summary> public Set(IEnumerable <A> items) { value = new SetInternal <OrdA, A>(items, true); }