KeyValuePair <TKey, TValue>?ISortedDictionary <TKey, TValue> .Higher(TKey key) { RBTree.Node highParent = null; RBTree.Node current = tree.root; while (current != null) { int cmp = hlp.Compare(key, current); if (cmp < 0) { highParent = current; current = current.left; } else if (cmp > 0) { current = current.right; } else { break; } } // we finished walk on a node with key equal to ours if (current != null && current.right != null) { return(((Node)current.right.FirstNode()).AsKV()); } if (highParent == null) { return(null); } else { return(((Node)highParent).AsKV()); } }