@Override public void update(ITupleReference newTuple, int oldTupleIndex, boolean inPlace) { frameTuple.resetByTupleIndex(this, oldTupleIndex); int oldTupleBytes = frameTuple.getTupleSize(); int slotOff = slotManager.getSlotOff(oldTupleIndex); int bytesWritten = 0; if (inPlace) { // Overwrite the old tuple in place. bytesWritten = tupleWriter.writeTuple(newTuple, buf.array(), buf.getInt(slotOff)); } else { // Insert the new tuple at the end of the free space, and change the // slot value (effectively "deleting" the old tuple). int newTupleOff = buf.getInt(Constants.FREE_SPACE_OFFSET); bytesWritten = tupleWriter.writeTuple(newTuple, buf.array(), newTupleOff); // Update slot value. buf.putInt(slotOff, newTupleOff); // Update contiguous free space pointer. buf.putInt(Constants.FREE_SPACE_OFFSET, newTupleOff + bytesWritten); } buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) + oldTupleBytes - bytesWritten); }
@Override public FrameOpSpaceStatus hasSpaceUpdate(ITupleReference newTuple, int oldTupleIndex) { frameTuple.resetByTupleIndex(this, oldTupleIndex); int oldTupleBytes = frameTuple.getTupleSize(); int newTupleBytes = tupleWriter.bytesRequired(newTuple); return hasSpaceUpdate(oldTupleBytes, newTupleBytes); }
@Override public void delete(ITupleReference tuple, int tupleIndex) { int slotOff = slotManager.getSlotOff(tupleIndex); int tupleOff; int keySize; if (tupleIndex == slotManager.getGreatestKeyIndicator()) { tupleOff = slotManager.getTupleOff(slotManager.getSlotEndOff()); frameTuple.resetByTupleOffset(buf.array(), tupleOff); keySize = frameTuple.getTupleSize(); // Copy new rightmost pointer. System.arraycopy(buf.array(), tupleOff + keySize, buf.array(), RIGHT_LEAF_OFFSET, CHILD_PTR_SIZE); } else { tupleOff = slotManager.getTupleOff(slotOff); frameTuple.resetByTupleOffset(buf.array(), tupleOff); keySize = frameTuple.getTupleSize(); // Perform deletion (we just do a memcpy to overwrite the slot). int slotStartOff = slotManager.getSlotEndOff(); int length = slotOff - slotStartOff; System.arraycopy(buf.array(), slotStartOff, buf.array(), slotStartOff + slotManager.getSlotSize(), length); } // Maintain space information. buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) - 1); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) + keySize + CHILD_PTR_SIZE + slotManager.getSlotSize()); }
@Override public FrameOpSpaceStatus hasSpaceUpdate(ITupleReference newTuple, int oldTupleIndex) { frameTuple.resetByTupleIndex(this, oldTupleIndex); int oldTupleBytes = frameTuple.getTupleSize(); int newTupleBytes = tupleWriter.bytesRequired(newTuple); FrameOpSpaceStatus status = hasSpaceUpdate(oldTupleBytes, newTupleBytes); if (status == FrameOpSpaceStatus.INSUFFICIENT_SPACE && (getLargeFlag() || getTupleCount() == 1) && isLargeTuple(newTupleBytes)) { return FrameOpSpaceStatus.EXPAND; } return status; }
interiorFrame.insert(mbrTuple, -1); interiorFrame.getBuffer().putInt( interiorFrame.getTupleOffset(interiorFrame.getTupleCount() - 1) + mbrTuple.getTupleSize(), prevPageId);
int sizeOfTwoTuples = 2 * (mbrTuple.getTupleSize() + RTreeNSMInteriorFrame.childPtrSize); FrameOpSpaceStatus spaceForTwoTuples = (((RTreeNSMInteriorFrame) interiorFrame).hasSpaceInsert(sizeOfTwoTuples)); interiorFrame.getTupleOffset(interiorFrame.getTupleCount() - 1) + mbrTuple.getTupleSize(), prevNodeFrontierPages.get(level - 1)); interiorFrame.getTupleOffset(interiorFrame.getTupleCount() - 1) + mbrTuple.getTupleSize(), prevNodeFrontierPages.get(level - 1));