@Override public void insertSorted(ITupleReference tuple) { insert(tuple, slotManager.getGreatestKeyIndicator()); }
@Override public void insertSorted(ITupleReference tuple) { int freeSpace = buf.getInt(Constants.FREE_SPACE_OFFSET); slotManager.insertSlot(slotManager.getGreatestKeyIndicator(), freeSpace); int bytesWritten = tupleWriter.writeTuple(tuple, buf, freeSpace); System.arraycopy(tuple.getFieldData(tuple.getFieldCount() - 1), getLeftChildPageOff(tuple), buf.array(), freeSpace + bytesWritten, CHILD_PTR_SIZE); int tupleSize = bytesWritten + CHILD_PTR_SIZE; buf.putInt(Constants.TUPLE_COUNT_OFFSET, buf.getInt(Constants.TUPLE_COUNT_OFFSET) + 1); buf.putInt(Constants.FREE_SPACE_OFFSET, buf.getInt(Constants.FREE_SPACE_OFFSET) + tupleSize); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) - tupleSize - slotManager.getSlotSize()); System.arraycopy(tuple.getFieldData(0), getLeftChildPageOff(tuple) + CHILD_PTR_SIZE, buf.array(), RIGHT_LEAF_OFFSET, CHILD_PTR_SIZE); }
@Override public ITupleReference getBeforeTuple(ITupleReference tuple, int targetTupleIndex, MultiComparator cmp) throws HyracksDataException { // Examine the tuple index to determine whether it is valid or not. if (targetTupleIndex != slotManager.getGreatestKeyIndicator()) { // We need to check the key to determine whether it's an insert or an update. frameTuple.resetByTupleIndex(this, targetTupleIndex); if (cmp.compare(tuple, frameTuple) == 0) { // The keys match, it's an update. return frameTuple; } } // Either the tuple index is a special indicator, or the keys don't match. // In those cases, we are definitely dealing with an insert. return null; } }
@Override public ITupleReference getMatchingKeyTuple(ITupleReference searchTuple, int targetTupleIndex) throws HyracksDataException { // Examine the tuple index to determine whether it is valid or not. if (targetTupleIndex != slotManager.getGreatestKeyIndicator()) { // We need to check the key to determine whether it's an insert or // an update/delete frameTuple.resetByTupleIndex(this, targetTupleIndex); if (cmp.compare(searchTuple, frameTuple) == 0) { // The keys match, it's an update/delete return frameTuple; } } // Either the tuple index is a special indicator, or the keys don't // match. // In those cases, we are definitely dealing with an insert. return null; }
@Override public int findUpdateTupleIndex(ITupleReference tuple) throws HyracksDataException { int tupleIndex; tupleIndex = slotManager.findTupleIndex(tuple, frameTuple, cmp, FindTupleMode.EXACT, FindTupleNoExactMatchPolicy.HIGHER_KEY); // Error indicator is set if there is no exact match. if (tupleIndex == slotManager.getErrorIndicator() || tupleIndex == slotManager.getGreatestKeyIndicator()) { throw HyracksDataException.create(ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY); } return tupleIndex; }
@Override public int findDeleteTupleIndex(ITupleReference tuple) throws HyracksDataException { int tupleIndex; tupleIndex = slotManager.findTupleIndex(tuple, frameTuple, cmp, FindTupleMode.EXACT, FindTupleNoExactMatchPolicy.HIGHER_KEY); // Error indicator is set if there is no exact match. if (tupleIndex == slotManager.getErrorIndicator() || tupleIndex == slotManager.getGreatestKeyIndicator()) { throw HyracksDataException.create(ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY); } return tupleIndex; }
@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()); }
int slotOff = slotManager.getSlotOff(tupleIndex); if (tupleIndex == slotManager.getGreatestKeyIndicator()) { return buf.getInt(RIGHT_LEAF_OFFSET);