for (int i = mid; i < length && array[i].getNodeId().isChildOf(parentId); i++) { switch (mode) { case NodeSet.DESCENDANT : if (Expression.NO_CONTEXT_ID != contextId) array[i].addContextNode(contextId, parent); else array[i].copyContext(parent); array[i].addMatches(parent); result.add(array[i]); break; case NodeSet.ANCESTOR : if (Expression.NO_CONTEXT_ID != contextId) parent.addContextNode(contextId, array[i]); else parent.copyContext(array[i]); parent.addMatches(array[i]); result.add(parent, 1); break; }
for (int i = mid; i < length; i++) { if (!array[i].getNodeId().isDescendantOf(parentId)) break; if (array[i].getNodeId().isChildOf(parentId)) { switch (mode) { case NodeSet.DESCENDANT : if (Expression.NO_CONTEXT_ID != contextId) array[i].addContextNode(contextId, parent); else array[i].copyContext(parent); array[i].addMatches(parent); result.add(array[i]); break; case NodeSet.ANCESTOR : if (Expression.NO_CONTEXT_ID != contextId) parent.addContextNode(contextId, array[i]); else parent.copyContext(array[i]); parent.addMatches(array[i]); result.add(parent, 1); break; } }
        NodeSet getChildrenInSet(NodeSet result, NodeProxy parent, int mode, int contextId) {            // get the range of node ids reserved for children of the parent            // node            int low = 0;            int high = length - 1;            int mid = 0;            int cmp;            NodeProxy p;            NodeId parentId = parent.getNodeId();            // do a binary search to pick some node in the range of valid child            // ids            while (low <= high) {                mid = (low + high) / 2;                p = array[mid];                if (p.getNodeId().isChildOf(parentId))                	break;	// found a child node, break out.                                cmp = p.getNodeId().compareTo(parentId);                if (cmp > 0)                    high = mid - 1;                else                    low = mid + 1;            }            if (low > high)                return result; // no node found            // find the first child node in the range            while (mid > 0 && array[mid - 1].getNodeId().compareTo(parentId) > 0)                --mid;            // walk through the range of child nodes we found            for (int i = mid; i < length && array[i].getNodeId().isChildOf(parentId); i++) {                switch (mode) {                    case NodeSet.DESCENDANT :                        if (Expression.NO_CONTEXT_ID != contextId)                            array[i].addContextNode(contextId, parent);                        else                            array[i].copyContext(parent);                        array[i].addMatches(parent);                        result.add(array[i]);                        break;                    case NodeSet.ANCESTOR :                        if (Expression.NO_CONTEXT_ID != contextId)                            parent.addContextNode(contextId, array[i]);                        else                            parent.copyContext(array[i]);                        parent.addMatches(array[i]);                        result.add(parent, 1);                        break;                }            }            return result;        }