@Override public void delete(int tupleIndex, MultiComparator cmp) { int slotOff = slotManager.getSlotOff(tupleIndex); int tupleOff = slotManager.getTupleOff(slotOff); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int tupleSize = tupleWriter.bytesRequired(frameTuple); // 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) + tupleSize + 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 delete(ITupleReference tuple, int tupleIndex) { int slotOff = slotManager.getSlotOff(tupleIndex); int tupleOff = slotManager.getTupleOff(slotOff); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int tupleSize = tupleWriter.bytesRequired(frameTuple); // 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) + tupleSize + slotManager.getSlotSize()); }
@Override public void delete(int tupleIndex, MultiComparator cmp) { frameTuple.setFieldCount(cmp.getKeyFieldCount()); int slotOff = slotManager.getSlotOff(tupleIndex); int tupleOff = slotManager.getTupleOff(slotOff); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int tupleSize = tupleWriter.bytesRequired(frameTuple); // 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) + tupleSize + childPtrSize + slotManager.getSlotSize()); }
@Override public boolean compact() { resetSpaceParams(); int tupleCount = buf.getInt(Constants.TUPLE_COUNT_OFFSET); int freeSpace = buf.getInt(Constants.FREE_SPACE_OFFSET); ArrayList<SlotOffTupleOff> sortedTupleOffs = new ArrayList<>(); sortedTupleOffs.ensureCapacity(tupleCount); for (int i = 0; i < tupleCount; i++) { int slotOff = slotManager.getSlotOff(i); int tupleOff = slotManager.getTupleOff(slotOff); sortedTupleOffs.add(new SlotOffTupleOff(i, slotOff, tupleOff)); } Collections.sort(sortedTupleOffs); for (int i = 0; i < sortedTupleOffs.size(); i++) { int tupleOff = sortedTupleOffs.get(i).tupleOff; frameTuple.resetByTupleOffset(buf.array(), tupleOff); int tupleEndOff = frameTuple.getFieldStart(frameTuple.getFieldCount() - 1) + frameTuple.getFieldLength(frameTuple.getFieldCount() - 1); int tupleLength = tupleEndOff - tupleOff + childPtrSize; System.arraycopy(buf.array(), tupleOff, buf.array(), freeSpace, tupleLength); slotManager.setSlot(sortedTupleOffs.get(i).slotOff, freeSpace); freeSpace += tupleLength; } buf.putInt(Constants.FREE_SPACE_OFFSET, freeSpace); buf.putInt(TOTAL_FREE_SPACE_OFFSET, buf.capacity() - freeSpace - tupleCount * slotManager.getSlotSize()); return false; }
sortedTupleOffs.ensureCapacity(tupleCount); for (int i = 0; i < tupleCount; i++) { int slotOff = slotManager.getSlotOff(i); int tupleOff = slotManager.getTupleOff(slotOff); sortedTupleOffs.add(new SlotOffTupleOff(i, slotOff, tupleOff));
public ArrayList<Integer> getChildren(MultiComparator cmp) { ArrayList<Integer> ret = new ArrayList<>(); frameTuple.setFieldCount(cmp.getKeyFieldCount()); int tupleCount = buf.getInt(Constants.TUPLE_COUNT_OFFSET); for (int i = 0; i < tupleCount; i++) { int tupleOff = slotManager.getTupleOff(slotManager.getSlotOff(i)); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int intVal = IntegerPointable.getInteger(buf.array(), frameTuple.getFieldStart(frameTuple.getFieldCount() - 1) + frameTuple.getFieldLength(frameTuple.getFieldCount() - 1)); ret.add(intVal); } return ret; }
sortedTupleOffs.ensureCapacity(tupleCount); for (int i = 0; i < tupleCount; i++) { int slotOff = slotManager.getSlotOff(i); int tupleOff = slotManager.getTupleOff(slotOff); sortedTupleOffs.add(new SlotOffTupleOff(i, slotOff, tupleOff));
public ArrayList<Integer> getChildren(MultiComparator cmp) { ArrayList<Integer> ret = new ArrayList<>(); frameTuple.setFieldCount(cmp.getKeyFieldCount()); int tupleCount = buf.getInt(Constants.TUPLE_COUNT_OFFSET); for (int i = 0; i < tupleCount; i++) { int tupleOff = slotManager.getTupleOff(slotManager.getSlotOff(i)); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int intVal = IntegerPointable.getInteger(buf.array(), frameTuple.getFieldStart(frameTuple.getFieldCount() - 1) + frameTuple.getFieldLength(frameTuple.getFieldCount() - 1)); ret.add(intVal); } if (!isLeaf()) { int rightLeaf = buf.getInt(RIGHT_LEAF_OFFSET); if (rightLeaf > 0) { ret.add(buf.getInt(RIGHT_LEAF_OFFSET)); } } return ret; }
@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);
rec[0].set(frameTuple, keyValueProviders); rightFrame.insert(frameTuple, -1); ((UnorderedSlotManager) slotManager).modifySlot(slotManager.getSlotOff(seed1), -1); totalBytes += leftRTreeFrame.getTupleSize(frameTuple); numOfDeletedTuples++; rightFrame.insert(frameTuple, -1); rec[0].enlarge(frameTuple, keyValueProviders); ((UnorderedSlotManager) slotManager).modifySlot(slotManager.getSlotOff(k), -1); totalBytes += leftRTreeFrame.getTupleSize(frameTuple); numOfDeletedTuples++;
rightFrame.insert(frameTuple, -1); ((UnorderedSlotManager) slotManager) .modifySlot(slotManager.getSlotOff(tupleEntries1.get(i).getTupleIndex()), -1); totalBytes += leftRTreeFrame.getTupleSize(frameTuple); numOfDeletedTuples++;