Ejemplo n.º 1
0
        /// <summary>
        /// Enumerates ring backwards starting at key preceding x.
        /// Skips duplicate values.
        /// </summary>
        public IEnumerable <KeyValuePair <TKey, TValue> > EnumerateFromNearestBackwardsDistinct(TKey key)
        {
            var items      = new HashSet <TValue>();
            var nearest    = GetNearestBackwards(key, _root);
            var enumerator = new EnumeratorDecreasing(_root, nearest, _comparer);

            while (enumerator.MoveNext())
            {
                if (items.Add(enumerator.Current.Value))
                {
                    yield return(enumerator.Current);
                }
            }

            enumerator = new EnumeratorDecreasing(_root);
            while (enumerator.MoveNext())
            {
                if (_comparer(enumerator.Current.Key, nearest.Key) == 0)
                {
                    yield break;
                }
                if (items.Add(enumerator.Current.Value))
                {
                    yield return(enumerator.Current);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Enumerates ring backwards starting at key preceding x.
        /// </summary>
        public IEnumerable <KeyValuePair <TKey, TValue> > EnumerateFromNearestBackwards(TKey key)
        {
            var nearest    = GetNearestBackwards(key, _root);
            var enumerator = new EnumeratorDecreasing(_root, nearest, _comparer);

            while (enumerator.MoveNext())
            {
                yield return(enumerator.Current);
            }

            enumerator = new EnumeratorDecreasing(_root);
            while (enumerator.MoveNext())
            {
                if (_comparer(enumerator.Current.Key, nearest.Key) == 0)
                {
                    yield break;
                }
                yield return(enumerator.Current);
            }
        }