static ILeafNode find()

in environment/src/main/java/jetbrains/exodus/tree/btree/BottomPage.java [165:211]


    static ILeafNode find(@NotNull BTreeTraverser stack, int depth, @NotNull ByteIterable key, @Nullable ByteIterable value, boolean equalOrNext, @NotNull BasePage page) {
        int index = page.binarySearch(key);
        if (index < 0) {
            if (value == null && equalOrNext) {
                index = -index - 1;
                if (index >= page.getSize()) return null; // after last element - no element to return
            } else {
                return null;
            }
        }

        ILeafNode ln = page.getKey(index);

        if (ln.isDup()) {
            BasePage dupRoot = ln.getTree().getRoot();
            ILeafNode dupLeaf;
            if (value != null) {
                // move dup cursor to requested value
                dupLeaf = dupRoot.find(stack, depth + 1, value, null, equalOrNext);
                if (dupLeaf == null) {
                    return null;
                }
            } else {
                dupLeaf = findFirst(stack, depth + 1, dupRoot);
            }

            stack.setAt(depth, new TreePos(page, index));

            ((BTreeTraverserDup) stack).inDupTree = true;

            return dupLeaf;
        }
        if (stack.isDup()) {
            ((BTreeTraverserDup) stack).inDupTree = false;
        }


        if (value == null || (equalOrNext ? value.compareTo(ln.getValue()) <= 0 : value.compareTo(ln.getValue()) == 0)) {
            stack.currentNode = page;
            stack.currentPos = index;
            stack.top = depth;
            //TODO: stack.bottom = 0?
            return ln;
        }

        return null;
    }