BTNode(long node) throws IndexException { this.node = node; this.chunk = BTree.this.db.getChunk(node); int i= 0; while (i < BTree.this.maxRecords && getRecord(this.chunk, node, i) != 0) i++; this.keyCount = i; }
BTNode(long node) throws IndexException { this.node = node; this.chunk = BTree.this.db.getChunk(node); int i= 0; while (i < BTree.this.maxRecords && getRecord(this.chunk, node, i) != 0) i++; this.keyCount = i; }
int indexLastNonBlankKey = 0; for (int i= 0; i < BTree.this.maxRecords; i++) { if (getRecord(BTree.this.db.getChunk(node), node, i) != 0) { keyCount++; indexLastNonBlankKey = i;
int indexLastNonBlankKey = 0; for (int i= 0; i < BTree.this.maxRecords; i++) { if (getRecord(BTree.this.db.getChunk(node), node, i) != 0) { keyCount++; indexLastNonBlankKey = i;
/** * Delete a section of node content - (key, (predecessor)child) pairs. Bounds checking * is not performed. To allow deletion of the final child (which has no corresponding key) * the routine behaves as though there were a corresponding key existing with value zero.<p> * Content is deleted and remaining content is moved leftward the appropriate amount. * @param node the node to delete content from * @param i the start index (inclusive) to delete from * @param length the length of the sequence to delete */ private void nodeContentDelete(BTNode node, int i, int length) { for (int index= i; index <= this.maxRecords; index++) { long newKey = (index + length) < node.keyCount ? getRecord(node.chunk, node.node, index + length) : 0; long newChild = (index + length) < node.keyCount + 1 ? getChild(node.chunk, node.node, index + length) : 0; if (index < this.maxRecords) { putRecord(node.chunk, node.node, index, newKey); } if (index < this.maxChildren) { putChild(node.chunk, node.node, index, newChild); } } }
/** * Delete a section of node content - (key, (predecessor)child) pairs. Bounds checking * is not performed. To allow deletion of the final child (which has no corresponding key) * the routine behaves as though there were a corresponding key existing with value zero.<p> * Content is deleted and remaining content is moved leftward the appropriate amount. * @param node the node to delete content from * @param i the start index (inclusive) to delete from * @param length the length of the sequence to delete */ private void nodeContentDelete(BTNode node, int i, int length) { for (int index= i; index <= this.maxRecords; index++) { long newKey = (index + length) < node.keyCount ? getRecord(node.chunk, node.node, index + length) : 0; long newChild = (index + length) < node.keyCount + 1 ? getChild(node.chunk, node.node, index + length) : 0; if (index < this.maxRecords) { putRecord(node.chunk, node.node, index, newKey); } if (index < this.maxChildren) { putChild(node.chunk, node.node, index, newChild); } } }
/** * Overwrite a section of the specified node (dst) with the specified section of the source * node. Bounds checking is not performed. To allow just copying of the final child (which has * no corresponding key) the routine behaves as though there were a corresponding key existing * with value zero.<p> * Copying from a node to itself is permitted. * @param src the node to read from * @param srcPos the initial index to read from (inclusive) * @param dst the node to write to * @param dstPos the initial index to write to (inclusive) * @param length the number of (key,(predecessor)child) nodes to write */ private void nodeContentCopy(BTNode src, int srcPos, BTNode dst, int dstPos, int length) { for (int i=length - 1; i >= 0; i--) { // this order is important when src == dst! int srcIndex = srcPos + i; int dstIndex = dstPos + i; if (srcIndex < src.keyCount + 1) { long srcChild = getChild(src.chunk, src.node, srcIndex); putChild(dst.chunk, dst.node, dstIndex, srcChild); if (srcIndex < src.keyCount) { long srcKey = getRecord(src.chunk, src.node, srcIndex); putRecord(dst.chunk, dst.node, dstIndex, srcKey); } } } }
/** * Overwrite a section of the specified node (dst) with the specified section of the source * node. Bounds checking is not performed. To allow just copying of the final child (which has * no corresponding key) the routine behaves as though there were a corresponding key existing * with value zero.<p> * Copying from a node to itself is permitted. * @param src the node to read from * @param srcPos the initial index to read from (inclusive) * @param dst the node to write to * @param dstPos the initial index to write to (inclusive) * @param length the number of (key,(predecessor)child) nodes to write */ private void nodeContentCopy(BTNode src, int srcPos, BTNode dst, int dstPos, int length) { for (int i=length - 1; i >= 0; i--) { // this order is important when src == dst! int srcIndex = srcPos + i; int dstIndex = dstPos + i; if (srcIndex < src.keyCount + 1) { long srcChild = getChild(src.chunk, src.node, srcIndex); putChild(dst.chunk, dst.node, dstIndex, srcChild); if (srcIndex < src.keyCount) { long srcKey = getRecord(src.chunk, src.node, srcIndex); putRecord(dst.chunk, dst.node, dstIndex, srcKey); } } } }
throws IndexException { nodeContentCopy(src, 0, dst, dst.keyCount + 1, src.keyCount + 1); long midKey = getRecord(keyProvider.chunk, keyProvider.node, kIndex); putRecord(dst.chunk, dst.node, dst.keyCount, midKey); long keySucc = kIndex + 1 == this.maxRecords ? 0 : getRecord(keyProvider.chunk, keyProvider.node, kIndex + 1); this.db.free(getChild(keyProvider.chunk, keyProvider.node, kIndex + 1), Database.POOL_BTREE); nodeContentDelete(keyProvider, kIndex + 1, 1);
throws IndexException { nodeContentCopy(src, 0, dst, dst.keyCount + 1, src.keyCount + 1); long midKey = getRecord(keyProvider.chunk, keyProvider.node, kIndex); putRecord(dst.chunk, dst.node, dst.keyCount, midKey); long keySucc = kIndex + 1 == this.maxRecords ? 0 : getRecord(keyProvider.chunk, keyProvider.node, kIndex + 1); this.db.free(getChild(keyProvider.chunk, keyProvider.node, kIndex + 1), Database.POOL_BTREE); nodeContentDelete(keyProvider, kIndex + 1, 1);
if (getRecord(chunk, node, this.maxRecords - 1) != 0) { long median = getRecord(chunk, node, this.medianRecord); if (median == record) { Chunk newchunk = this.db.getChunk(newnode); for (int i = 0; i < this.medianRecord; ++i) { putRecord(newchunk, newnode, i, getRecord(chunk, node, this.medianRecord + 1 + i)); putRecord(chunk, node, this.medianRecord + 1 + i, 0); putChild(newchunk, newnode, i, getChild(chunk, node, this.medianRecord + 1 + i)); long r = getRecord(pChunk, parent, i); if (r != 0) { while (lower < upper && getRecord(chunk, node, upper - 1) == 0) { upper--; long checkRec= getRecord(chunk, node, middle); if (checkRec == 0) { upper= middle; long r = getRecord(chunk, node, j); if (r != 0) putRecord(chunk, node, j + 1, r);
if (getRecord(chunk, node, this.maxRecords - 1) != 0) { long median = getRecord(chunk, node, this.medianRecord); if (median == record) { Chunk newchunk = this.db.getChunk(newnode); for (int i = 0; i < this.medianRecord; ++i) { putRecord(newchunk, newnode, i, getRecord(chunk, node, this.medianRecord + 1 + i)); putRecord(chunk, node, this.medianRecord + 1 + i, 0); putChild(newchunk, newnode, i, getChild(chunk, node, this.medianRecord + 1 + i)); long r = getRecord(pChunk, parent, i); if (r != 0) { while (lower < upper && getRecord(chunk, node, upper - 1) == 0) { upper--; long checkRec= getRecord(chunk, node, middle); if (checkRec == 0) { upper= middle; long r = getRecord(chunk, node, j); if (r != 0) putRecord(chunk, node, j + 1, r);
if (mode == DELMODE_NORMAL) for (int i= 0; i < node.keyCount; i++) if (getRecord(node.chunk, node.node, i) == key) { keyIndexInNode = i; break; } else { if (mode == DELMODE_DELETE_MINIMUM) { long subst = getRecord(node.chunk, node.node, 0); nodeContentDelete(node, 0, 1); return subst; } else if (mode == DELMODE_DELETE_MAXIMUM) { long subst = getRecord(node.chunk, node.node, node.keyCount - 1); nodeContentDelete(node, node.keyCount - 1, 1); return subst; subtreeIndex = node.keyCount; for (int i= 0; i < node.keyCount; i++) if (this.cmp.compare(this.nd, getRecord(node.chunk, node.node, i), key)>0) { subtreeIndex = i; break; long rightKey = getRecord(node.chunk, node.node, subtreeIndex); long leftmostRightSiblingKey = getRecord(sibR.chunk, sibR.node, 0); append(child, rightKey, getChild(sibR.chunk, sibR.node, 0)); nodeContentDelete(sibR, 0, 1); long leftKey = getRecord(node.chunk, node.node, subtreeIndex - 1); prepend(child, leftKey, getChild(sibL.chunk, sibL.node, sibL.keyCount));
if (mode == DELMODE_NORMAL) for (int i= 0; i < node.keyCount; i++) if (getRecord(node.chunk, node.node, i) == key) { keyIndexInNode = i; break; } else { if (mode == DELMODE_DELETE_MINIMUM) { long subst = getRecord(node.chunk, node.node, 0); nodeContentDelete(node, 0, 1); return subst; } else if (mode == DELMODE_DELETE_MAXIMUM) { long subst = getRecord(node.chunk, node.node, node.keyCount - 1); nodeContentDelete(node, node.keyCount - 1, 1); return subst; subtreeIndex = node.keyCount; for (int i= 0; i < node.keyCount; i++) if (this.cmp.compare(this.nd, getRecord(node.chunk, node.node, i), key)>0) { subtreeIndex = i; break; long rightKey = getRecord(node.chunk, node.node, subtreeIndex); long leftmostRightSiblingKey = getRecord(sibR.chunk, sibR.node, 0); append(child, rightKey, getChild(sibR.chunk, sibR.node, 0)); nodeContentDelete(sibR, 0, 1); long leftKey = getRecord(node.chunk, node.node, subtreeIndex - 1); prepend(child, leftKey, getChild(sibL.chunk, sibL.node, sibL.keyCount));