public long getNext(long key){
        if (key < 0) {
            throw new IndexOutOfBoundsException();
        }

        boolean foundValue = false;
        long bestkey = 0;

        RBNode node = root;
        while (node != null) {
            if (key >= node.key) {
                node = node.right;
            }
            else {
                foundValue = true;
                bestkey = node.key;
                node = node.left;
            }

        }
        if (foundValue) {
            return bestkey;
        }
		return -1;

    }
Returns the smallest key in the set that is greater than the given key.  Returns
-1 if there are no keys greater than the given key.
@param key the key for which to find the next key after.
@exception IndexOutOfBoundsException thrown if the given key is not
in the range [0, maxKey].
Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/RedBlackLongKeySet.java