@Override public void insert(ITupleReference tuple, int tupleIndex) { slotManager.insertSlot(tupleIndex, buf.getInt(Constants.FREE_SPACE_OFFSET)); int bytesWritten = tupleWriter.writeTuple(tuple, buf.array(), buf.getInt(Constants.FREE_SPACE_OFFSET)); 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) + bytesWritten); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) - bytesWritten - slotManager.getSlotSize()); }
@Override public void insert(ITupleReference tuple, int tupleIndex) { int freeSpace = buf.getInt(Constants.FREE_SPACE_OFFSET); slotManager.insertSlot(tupleIndex, freeSpace); int bytesWritten = tupleWriter.writeTuple(tuple, buf.array(), freeSpace); 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) + bytesWritten); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) - bytesWritten - slotManager.getSlotSize()); }
@Override public void insert(ITupleReference tuple, int tupleIndex) { slotManager.insertSlot(-1, buf.getInt(Constants.FREE_SPACE_OFFSET)); int bytesWritten = tupleWriter.writeTuple(tuple, buf.array(), buf.getInt(Constants.FREE_SPACE_OFFSET)); 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) + bytesWritten); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.getInt(TOTAL_FREE_SPACE_OFFSET) - bytesWritten - slotManager.getSlotSize()); }
@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 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 void adjustKey(ITupleReference tuple, int tupleIndex, MultiComparator cmp) throws HyracksDataException { frameTuple.setFieldCount(cmp.getKeyFieldCount()); if (tupleIndex == -1) { tupleIndex = findTupleByPointer(tuple, cmp); } if (tupleIndex != -1) { tupleWriter.writeTuple(tuple, buf.array(), getTupleOffset(tupleIndex)); } else { throw HyracksDataException.create(ErrorCode.FAILED_TO_FIND_TUPLE); } }
opCallback.after(tuple); logged = true; tupleWriter.writeTuple(tuple, minTupleBytes, 0); minTupleBuf = ByteBuffer.wrap(minTupleBytes); minTuple = tupleWriter.createTupleReference(); if (minTupleBytes.length < numBytes) { minTupleBytes = new byte[numBytes]; tupleWriter.writeTuple(tuple, minTupleBytes, 0); minTupleBuf = ByteBuffer.wrap(minTupleBytes); } else { tupleWriter.writeTuple(tuple, minTupleBytes, 0); opCallback.after(tuple); tupleWriter.writeTuple(tuple, maxTupleBytes, 0); maxTupleBuf = ByteBuffer.wrap(maxTupleBytes); maxTuple = tupleWriter.createTupleReference(); if (maxTupleBytes.length < numBytes) { maxTupleBytes = new byte[numBytes]; tupleWriter.writeTuple(tuple, maxTupleBytes, 0); maxTupleBuf = ByteBuffer.wrap(maxTupleBytes); } else { tupleWriter.writeTuple(tuple, maxTupleBytes, 0);
@Override public void writeMaxTuple(ITupleReference tuple) { binaryFilter.reset(); max.reset(); max.setSize(tupleWriter.bytesRequired(tuple)); tupleWriter.writeTuple(tuple, max.getByteArray(), 0); }
@Override public void writeMinTuple(ITupleReference tuple) { binaryFilter.reset(); min.reset(); min.setSize(tupleWriter.bytesRequired(tuple)); tupleWriter.writeTuple(tuple, min.getByteArray(), 0); }
int splitKeySize = tupleWriter.bytesRequired(frameTuple, 0, cmp.getKeyFieldCount()); splitKey.initData(splitKeySize); tupleWriter.writeTuple(frameTuple, splitKey.getBuffer(), 0); splitKey.getTuple().resetByTupleOffset(splitKey.getBuffer().array(), 0);