private static RBNode buildFromSorted(int level, int lo, int hi,
                                         int redLevel,
                                         java.io.ObjectInputStream str)
        throws  java.io.IOException, ClassNotFoundException {
        /*
         * Strategy: The root is the middlemost element. To get to it, we
         * have to first recursively construct the entire left subtree,
         * so as to grab all of its elements. We can then proceed with right
         * subtree.
         *
         * The lo and hi arguments are the minimum and maximum
         * indices to pull out of the iterator or stream for current subtree.
         * They are not actually indexed, we just proceed sequentially,
         * ensuring that items are extracted in corresponding order.
         */

        if (hi < lo) return null;

        int mid = (lo + hi) / 2;

        RBNode left  = null;
        if (lo < mid) {
            left = buildFromSorted(level+1, lo, mid - 1, redLevel, str);
        }
        // extract from stream
        long key = str.readLong();


        RBNode middle =  new RBNode(key, null);

        // color nodes in non-full bottommost level red
        if (level == redLevel)
            middle.color = RED;

        if (left != null) {
            middle.left = left;
            left.parent = middle;
        }

        if (mid < hi) {
            RBNode right = buildFromSorted(level+1, mid+1, hi, redLevel, str);
            middle.right = right;
            right.parent = middle;
        }

        return middle;
    }
Recursive "helper method" that does the real work of the
of the previous method.  Identically named parameters have
identical definitions.  Additional parameters are documented below.
It is assumed that the comparator and size fields of the TreeMap are
already set prior to calling this method.  (It ignores both fields.)

@param level the current level of tree. Initial call should be 0.
@param lo the first element index of this subtree. Initial should be 0.
@param hi the last element index of this subtree.  Initial should be
	      size-1.
@param redLevel the level at which nodes should be red.
       Must be equal to computeRedLevel for tree of this size.
Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/RedBlackLongKeySet.java