public HSetInternal <T> Subtract(HSetInternal <T> rhs) { var self = this; foreach (var item in rhs) { self = self.Remove(item); } return(self); }
public HSetInternal <T> Append(HSetInternal <T> rhs) { var self = this; foreach (var item in rhs) { if (!self.Contains(item)) { self = self.Add(item); } } return(self); }
public bool IsSubsetOf(IEnumerable <T> other) { if (IsEmpty) { return(true); } var otherSet = new HSetInternal <T>(other); int matches = 0; foreach (var item in otherSet) { if (Contains(item)) { matches++; } } return(matches == Count); }
internal HSetInternal(IEnumerable <T> items, bool checkUniqueness = false) { var set = new HSetInternal <T>(); if (checkUniqueness) { foreach (var item in items) { set = set.TryAdd(item); } } else { foreach (var item in items) { set = set.Add(item); } } }
public bool Equals(HSetInternal <T> other) { if (other == null || Count != other.Count) { return(false); } var iterx = GetEnumerator(); var itery = other.GetEnumerator(); var eq = EqualityComparer <T> .Default; for (int i = 0; i < count; i++) { iterx.MoveNext(); itery.MoveNext(); if (!eq.Equals(iterx.Current, itery.Current)) { return(false); } } return(true); }
public bool IsProperSubsetOf(IEnumerable <T> other) { if (IsEmpty) { return(other.Any()); } var otherSet = new HSetInternal <T>(other); if (Count >= otherSet.Count) { return(false); } int matches = 0; bool extraFound = false; foreach (var item in otherSet) { if (Contains(item)) { matches++; } else { extraFound = true; } if (matches == Count && extraFound) { return(true); } } return(false); }
/// <summary> /// Ctor that takes an initial (distinct) set of items /// </summary> /// <param name="items"></param> internal HSet(IEnumerable <T> items, bool checkUniqueness = false) { value = new HSetInternal <T>(items, checkUniqueness); }
static HSet <U> Wrap <U>(HSetInternal <U> value) => new HSet <U>(value);
HSet <T> Wrap(HSetInternal <T> value) => new HSet <T>(value);
internal HSet(HSetInternal <T> value) { this.value = value; }