NodeCursor<K> descendToFirstChild(boolean forwards) { if (isLeaf()) { position = forwards ? 0 : getLeafKeyEnd(node) - 1; return null; } inChild = true; position = forwards ? 0 : getChildCount(node) - 1; return descend(); }
Object[] toNode() { // we permit building empty trees as some constructions do not know in advance how many items they will contain assert buildKeyPosition <= FAN_FACTOR : buildKeyPosition; return buildFromRange(0, buildKeyPosition, isLeaf(copyFrom), false); }
NodeCursor(Object[] node, NodeCursor<K> parent, Comparator<? super K> comparator) { this.node = node; this.parent = parent; this.comparator = comparator; // a well formed b-tree (text book, or ours) must be balanced, so by building a stack following the left-most branch // we have a stack capable of visiting any path in the tree this.child = BTree.isLeaf(node) ? null : new NodeCursor<>((Object[]) node[getChildStart(node)], this, comparator); }
NodeCursor<K> descend() { Object[] childNode = (Object[]) node[position + getChildStart(node)]; int childOffset = nodeOffset + treeIndexOffsetOfChild(node, position); child.resetNode(childNode, childOffset); inChild = true; return child; }
void addNewKey(Object key) { ensureRoom(buildKeyPosition + 1); buildKeys[buildKeyPosition++] = updateFunction.apply(key); }
@Override public BTreeSet<V> headSet(V toElement, boolean inclusive) { return super.tailSet(toElement, inclusive).descendingSet(); }
@Override public BTreeSet<V> subSet(V fromElement, boolean fromInclusive, V toElement, boolean toInclusive) { return super.subSet(toElement, toInclusive, fromElement, fromInclusive).descendingSet(); }
NodeCursor<K> descendToFirstChild(boolean forwards) { if (isLeaf()) { position = forwards ? 0 : getLeafKeyEnd(node) - 1; return null; } inChild = true; position = forwards ? 0 : getChildCount(node) - 1; return descend(); }
Object[] toNode() { // we permit building empty trees as some constructions do not know in advance how many items they will contain assert buildKeyPosition <= FAN_FACTOR : buildKeyPosition; return buildFromRange(0, buildKeyPosition, isLeaf(copyFrom), false); }
@Override public BTreeSet<V> headSet(V toElement, boolean inclusive) { return super.tailSet(toElement, inclusive).descendingSet(); }