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); }
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); }
public static int depth(Object[] tree) { int depth = 1; while (!isLeaf(tree)) { depth++; tree = (Object[]) tree[getKeyEnd(tree)]; } return depth; }
public static int depth(Object[] tree) { int depth = 1; while (!isLeaf(tree)) { depth++; tree = (Object[]) tree[getKeyEnd(tree)]; } return depth; }
public static int depth(Object[] tree) { int depth = 1; while (!isLeaf(tree)) { depth++; tree = (Object[]) tree[getKeyEnd(tree)]; } return depth; }
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); }
public static int size(Object[] tree) { if (isLeaf(tree)) return getLeafKeyEnd(tree); int length = tree.length; // length - 1 == getChildEnd == getPositionOfSizeMap // (length / 2) - 1 == getChildCount - 1 == position of full tree size // hard code this, as will be used often; return ((int[]) tree[length - 1])[(length / 2) - 1]; }
public static int size(Object[] tree) { if (isLeaf(tree)) return getLeafKeyEnd(tree); int length = tree.length; // length - 1 == getChildEnd == getPositionOfSizeMap // (length / 2) - 1 == getChildCount - 1 == position of full tree size // hard code this, as will be used often; return ((int[]) tree[length - 1])[(length / 2) - 1]; }
private static int copyChildren(final Object[] from, final Object[] to, final int offset, final int skipIndex) { assert !BTree.isLeaf(from); final int start = BTree.getChildStart(from); final int childCount = BTree.getChildCount(from); if (skipIndex > 0) System.arraycopy(from, start, to, offset, skipIndex); if (skipIndex + 1 <= childCount) System.arraycopy(from, start + skipIndex + 1, to, offset + skipIndex, childCount - skipIndex - 1); return offset + childCount - 1; }
private static int copyChildren(final Object[] from, final Object[] to, final int offset, final int skipIndex) { assert !BTree.isLeaf(from); final int start = BTree.getChildStart(from); final int childCount = BTree.getChildCount(from); if (skipIndex > 0) System.arraycopy(from, start, to, offset, skipIndex); if (skipIndex + 1 <= childCount) System.arraycopy(from, start + skipIndex + 1, to, offset + skipIndex, childCount - skipIndex - 1); return offset + childCount - 1; }
private static int copyChildren(final Object[] from, final Object[] to, final int offset, final int skipIndex) { assert !BTree.isLeaf(from); final int start = BTree.getChildStart(from); final int childCount = BTree.getChildCount(from); if (skipIndex > 0) System.arraycopy(from, start, to, offset, skipIndex); if (skipIndex + 1 <= childCount) System.arraycopy(from, start + skipIndex + 1, to, offset + skipIndex, childCount - skipIndex - 1); return offset + childCount - 1; }
private static int copyChildren(final Object[] from, final Object[] to, final int offset) { assert !BTree.isLeaf(from); final int start = BTree.getChildStart(from); final int childCount = BTree.getChildCount(from); System.arraycopy(from, start, to, offset, childCount); return offset + childCount; }
private static int copyChildren(final Object[] from, final Object[] to, final int offset) { assert !BTree.isLeaf(from); final int start = BTree.getChildStart(from); final int childCount = BTree.getChildCount(from); System.arraycopy(from, start, to, offset, childCount); return offset + childCount; }
private static int copyChildren(final Object[] from, final Object[] to, final int offset) { assert !BTree.isLeaf(from); final int start = BTree.getChildStart(from); final int childCount = BTree.getChildCount(from); System.arraycopy(from, start, to, offset, childCount); return offset + childCount; }
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); }
static int getKeyEnd(Object[] node) { if (isLeaf(node)) return getLeafKeyEnd(node); else return getBranchKeyEnd(node); }
static int getKeyEnd(Object[] node) { if (isLeaf(node)) return getLeafKeyEnd(node); else return getBranchKeyEnd(node); }
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); }
static int getKeyEnd(Object[] node) { if (isLeaf(node)) return getLeafKeyEnd(node); else return getBranchKeyEnd(node); }
public static long sizeOfStructureOnHeap(Object[] tree) { long size = ObjectSizes.sizeOfArray(tree); if (isLeaf(tree)) return size; for (int i = getChildStart(tree) ; i < getChildEnd(tree) ; i++) size += sizeOfStructureOnHeap((Object[]) tree[i]); return size; }