/// <summary> /// Determines whether the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> and the specified collection contain the same elements. /// </summary> /// <param name="other">The collection to compare to the current set.</param> /// <returns>true if the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> is equal to <paramref name="other"/>; otherwise, false.</returns> public bool SetEquals(IEnumerable <T> other) { if (other == null) { Thrower.ArgumentNullException(ArgumentType.other); } ICommonSortedSet <T> sortedset = SetHelper <T> .GetSortedSetIfSameComparer(this, Comparer); if (sortedset != null) { IEnumerator <T> e1 = this.GetEnumerator(); IEnumerator <T> e2 = sortedset.GetEnumerator(); bool canMove1 = e1.MoveNext(); bool canMove2 = e2.MoveNext(); while (canMove1 && canMove2) { if (_comparer.Compare(e1.Current, e2.Current) != 0) { return(false); } canMove1 = e1.MoveNext(); canMove2 = e2.MoveNext(); } return(canMove1 == canMove2); } return(SetHelper <T> .SetEquals(this, other)); }
/// <summary> /// Determines whether the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> overlaps with the specified collection. /// </summary> /// <param name="other">The collection to compare to the current set.</param> /// <returns>true if the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> and <paramref name="other"/> share at least one common element; otherwise, false.</returns> public bool Overlaps(IEnumerable <T> other) { if (other == null) { Thrower.ArgumentNullException(ArgumentType.other); } if (Count == 0) { return(false); } if (CollectionHelper.IsWellKnownCollection <T>(other, out int num)) { if (num == 0) { return(false); } ICommonSortedSet <T> sortedset = SetHelper <T> .GetSortedSetIfSameComparer(this, Comparer); if (sortedset != null) { if ((_comparer.Compare(MinValue, sortedset.MaxValue) > 0) || (_comparer.Compare(MaxValue, sortedset.MinValue) < 0)) { return(false); } } foreach (T item in other) { if (Contains(item)) { return(true); } } } return(false); }
/// <summary> /// Determines whether the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> is a subset of a specified collection. /// </summary> /// <param name="other">The collection to compare to the current set.</param> /// <returns>true if the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> is a subset of the specified collection; otherwise, false.</returns> public bool IsSubsetOf(IEnumerable <T> other) { if (other == null) { Thrower.ArgumentNullException(ArgumentType.other); } if (this.Count == 0) { return(true); } ICommonSortedSet <T> sortedset = SetHelper <T> .GetSortedSetIfSameComparer(this, Comparer); if (sortedset != null) { if (this.Count > sortedset.Count) { return(false); } ICommonSortedSet <T> subset = sortedset.GetViewBetween(MinValue, MaxValue); foreach (T item in this) { if (!subset.Contains(item)) { return(false); } } return(true); } return(SetHelper <T> .IsSubsetOf(this, other)); }
/// <summary> /// Determines whether the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> is a superset of a specified collection. /// </summary> /// <param name="other">The collection to compare to the current set.</param> /// <returns>true if the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> is a superset of <paramref name="other"/>; otherwise, false.</returns> public bool IsSupersetOf(IEnumerable <T> other) { if (other == null) { Thrower.ArgumentNullException(ArgumentType.other); } if (CollectionHelper.IsWellKnownCollection(other, out int num)) { if (num == 0) { return(true); } if (SetHelper <T> .IsWellKnownSet(other)) { if (this.Count < num) { return(false); } } } ICommonSortedSet <T> sortedset = SetHelper <T> .GetSortedSet(other); if ((sortedset == null) || !AreEqualComparers(this._comparer, sortedset.Comparer)) { return(this.ContainsSequence(other)); } ReadOnlySortedSet <T> subset = this.GetViewBetween(sortedset.MinValue, sortedset.MaxValue); foreach (T item in sortedset) { if (!subset.Contains(item)) { return(false); } } return(true); }