public void SymmetricExceptWith(IEnumerable <T> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (Count == 0)
            {
                UnionWith(other);
                return;
            }

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

            if (other is SortedTreeSet <T> sortedSet && Comparer.Equals(sortedSet.Comparer))
            {
                foreach (T item in other)
                {
                    if (!Remove(item))
                    {
                        Add(item);
                    }
                }

                return;
            }

            sortedSet = new SortedTreeSet <T>(other, Comparer);
            SymmetricExceptWith(sortedSet);
        }
        public void IntersectWith(IEnumerable <T> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (Count == 0)
            {
                return;
            }

            if (this == other)
            {
                return;
            }

            if (other is SortedTreeSet <T> sortedSet && Comparer.Equals(sortedSet.Comparer))
            {
                int i = 0;
                int j = 0;
                while (i < Count && j < sortedSet.Count)
                {
                    int comparison = Comparer.Compare(_sortedList[i], sortedSet._sortedList[j]);
                    if (comparison == 0)
                    {
                        // Keep the item
                        i++;
                        j++;
                    }
                    else if (comparison < 0)
                    {
                        _sortedList.RemoveAt(i);
                    }
                    else
                    {
                        // The item may be present, but it's not the current item
                        j++;
                    }
                }

                _sortedList.RemoveRange(i, Count - i);
            }
            else
            {
                var toSave = new SortedTreeSet <T>(Comparer);
                foreach (T item in other)
                {
                    if (Contains(item))
                    {
                        toSave.Add(item);
                    }
                }

                IntersectWith(toSave);
            }
        }
            public int GetHashCode(SortedTreeSet <T> obj)
            {
                if (obj == null)
                {
                    return(0);
                }

                int hashCode = 0;

                foreach (T item in obj)
                {
                    hashCode = hashCode ^ _equalityComparer.GetHashCode(item);
                }

                return(hashCode);
            }
            public bool Equals(SortedTreeSet <T> x, SortedTreeSet <T> y)
            {
                if (x is null)
                {
                    return(y is null);
                }
                else if (y is null)
                {
                    return(false);
                }

                if (x.Comparer.Equals(y.Comparer))
                {
                    return(x.SetEquals(y));
                }

                bool found = false;

                foreach (T item1 in x)
                {
                    found = false;
                    foreach (T item2 in y)
                    {
                        if (_comparer.Compare(item1, item2) == 0)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        return(false);
                    }
                }

                return(true);
            }
 public SortedTreeDictionary(int branchingFactor, IComparer <TKey>?comparer)
 {
     _comparer = comparer ?? Comparer <TKey> .Default;
     _treeSet  = new SortedTreeSet <KeyValuePair <TKey, TValue> >(branchingFactor, new KeyOfPairComparer <TKey, TValue>(_comparer));
 }
 public SortedTreeDictionary(IComparer <TKey>?comparer)
 {
     _comparer = comparer ?? Comparer <TKey> .Default;
     _treeSet  = new SortedTreeSet <KeyValuePair <TKey, TValue> >(new KeyOfPairComparer <TKey, TValue>(_comparer));
 }
Beispiel #7
0
 internal Enumerator(SortedTreeSet <KeyValuePair <TKey, TValue> > .Enumerator enumerator, ReturnType returnType)
 {
     _returnType = returnType;
     _enumerator = enumerator;
 }