コード例 #1
0
        public bool IsProperSupersetOf(IEnumerable <T> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (Count == 0)
            {
                return(false);
            }

            if (this == other)
            {
                return(false);
            }

            if (other is ICollection collection && collection.Count == 0)
            {
                Debug.Assert(Count > 0, $"Assertion failed: {nameof(Count)} > 0");
                return(true);
            }

            if (other is SortedTreeSet <T> sortedSet && Comparer.Equals(sortedSet.Comparer))
            {
                if (sortedSet.Count >= Count)
                {
                    return(false);
                }

                foreach (T item in sortedSet)
                {
                    if (!Contains(item))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            (int uniqueCount, int unfoundCount) = SetHelper.CheckUniqueAndUnfoundElements(_sortedList, other, returnIfUnfound: true);
            return(uniqueCount < Count && unfoundCount == 0);
        }
コード例 #2
0
        public bool SetEquals(IEnumerable <T> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (this == other)
            {
                return(true);
            }

            if (other is SortedTreeSet <T> sortedSet && Comparer.Equals(sortedSet.Comparer))
            {
                if (Count != sortedSet.Count)
                {
                    return(false);
                }

                Enumerator x = GetEnumerator();
                Enumerator y = sortedSet.GetEnumerator();
                while (true)
                {
                    bool hasX = x.MoveNext();
                    bool hasY = y.MoveNext();
                    Debug.Assert(hasX == hasY, $"Assertion failed: {nameof(hasX)} == {nameof(hasY)}");
                    if (!hasX)
                    {
                        return(true);
                    }

                    if (Comparer.Compare(x.Current, y.Current) != 0)
                    {
                        return(false);
                    }
                }
            }

            (int uniqueCount, int unfoundCount) = SetHelper.CheckUniqueAndUnfoundElements(_sortedList, other, returnIfUnfound: true);
            return(uniqueCount == Count && unfoundCount == 0);
        }