Ejemplo n.º 1
0
        /// <summary>
        /// Enumerates the nodes whose keys satisfy the given range predicate.
        /// </summary>
        /// <param name="rangePredicate">Must not conflict with the comparison delegate.</param>
        public IEnumerable <TNode> FindRange(KeyRangePredicate rangePredicate)
        {
            TNode first = FindRangeMin(rangePredicate);

            if (first == null)
            {
                yield break;
            }
            TNode last = FindRangeMax(rangePredicate);

            last = last.successor;
            for (TNode node = first; node != last; node = node.successor)
            {
                yield return(node);
            }
        }
Ejemplo n.º 2
0
        private TNode FindRangeExtremum(KeyRangePredicate rangePredicate, RBTreeDirection direction)
        {
            TNode extremum = null;
            TNode node     = Root;

            while (node != SentinelNode)
            {
                int result = rangePredicate(node.Key);
                if (result == 0)
                {
                    extremum = node;
                    node     = node.GetChild(direction);
                }
                else if (result < 0)
                {
                    node = node.right;
                }
                else
                {
                    node = node.left;
                }
            }
            return(extremum);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Of the nodes whose keys satisfy the given range predicate,
 /// returns the one with maximum key, if it exists.
 /// Otherwise, returns null.
 /// </summary>
 /// <param name="rangePredicate">Must not conflict with the comparison delegate.</param>
 public TNode FindRangeMax(KeyRangePredicate rangePredicate)
 {
     return(FindRangeExtremum(rangePredicate, RBTreeDirection.Right));
 }