private Insert updateRecursive()

in accord-core/src/main/java/accord/utils/btree/BTree.java [3483:3537]


        private Insert updateRecursive(Insert ik, Object[] unode, Existing uub, LeafBuilder builder)
        {
            int upos = 0;
            int usz = sizeOfLeaf(unode);
            Existing uk = (Existing) unode[upos];
            int c = comparator.compare(uk, ik);

            while (true)
            {
                if (c == 0)
                {
                    leaf().addKey(updateF.merge(uk, ik));
                    if (++upos < usz)
                        uk = (Existing) unode[upos];
                    ik = insert.next();
                    if (ik == null)
                    {
                        builder.copy(unode, upos, usz - upos);
                        return null;
                    }
                    if (upos == usz)
                        break;
                    c = comparator.compare(uk, ik);
                }
                else if (c < 0)
                {
                    int ulim = exponentialSearch(comparator, unode, upos + 1, usz, ik);
                    c = -searchResultToComparison(ulim); // 0 if match, 1 otherwise
                    if (ulim < 0)
                        ulim = -(1 + ulim);
                    builder.copy(unode, upos, ulim - upos);
                    if ((upos = ulim) == usz)
                        break;
                    uk = (Existing) unode[upos];
                }
                else
                {
                    builder.addKey(isSimple(updateF) ? ik : updateF.insert(ik));
                    c = insert.copyKeysSmallerThan(uk, comparator, builder, updateF); // 0 on match, -1 otherwise
                    ik = insert.next();
                    if (ik == null)
                    {
                        builder.copy(unode, upos, usz - upos);
                        return null;
                    }
                }
            }
            if (uub == null || comparator.compare(ik, uub) < 0)
            {
                builder.addKey(isSimple(updateF) ? ik : updateF.insert(ik));
                insert.copyKeysSmallerThan(uub, comparator, builder, updateF); // 0 on match, -1 otherwise
                ik = insert.next();
            }
            return ik;
        }