@Override public void deleteGreatest() { int slotOff = slotManager.getSlotEndOff(); int tupleOff = slotManager.getTupleOff(slotOff); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int keySize = tupleWriter.bytesRequired(frameTuple); System.arraycopy(buf.array(), tupleOff + keySize, buf.array(), RIGHT_LEAF_OFFSET, CHILD_PTR_SIZE); // 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 freeSpace = buf.getInt(Constants.FREE_SPACE_OFFSET); if (freeSpace == tupleOff + keySize + CHILD_PTR_SIZE) { buf.putInt(freeSpace, freeSpace - (keySize + CHILD_PTR_SIZE)); } }
@Override public int getLeftmostChildPageId() { int tupleOff = slotManager.getTupleOff(slotManager.getSlotStartOff()); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int childPageOff = getLeftChildPageOff(frameTuple); return buf.getInt(childPageOff); }
@Override public int getTupleOffset(int slotNum) { return slotManager.getTupleOff(slotManager.getSlotStartOff() - slotNum * slotManager.getSlotSize()); }
@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) { 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 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 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; }
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; }
for (int i = 0; i < tupleCount; i++) { int slotOff = slotManager.getSlotOff(i); int tupleOff = slotManager.getTupleOff(slotOff); sortedTupleOffs.add(new SlotOffTupleOff(i, slotOff, tupleOff));
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 insert(ITupleReference tuple, int tupleIndex) { int slotOff = slotManager.insertSlot(tupleIndex, buf.getInt(Constants.FREE_SPACE_OFFSET)); int freeSpace = buf.getInt(Constants.FREE_SPACE_OFFSET); int bytesWritten = tupleWriter.writeTupleFields(tuple, 0, tuple.getFieldCount(), buf.array(), 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()); // Did we insert into the rightmost slot? if (slotOff == slotManager.getSlotEndOff()) { System.arraycopy(tuple.getFieldData(tuple.getFieldCount() - 1), getLeftChildPageOff(tuple) + CHILD_PTR_SIZE, buf.array(), RIGHT_LEAF_OFFSET, CHILD_PTR_SIZE); } else { // If slotOff has a right (slot-)neighbor then update its child pointer. // The only time when this is NOT the case, is when this is the very first tuple // (or when the splitkey goes into the rightmost slot but that case is handled in the if above). if (buf.getInt(Constants.TUPLE_COUNT_OFFSET) > 1) { int rightNeighborOff = slotOff - slotManager.getSlotSize(); frameTuple.resetByTupleOffset(buf.array(), slotManager.getTupleOff(rightNeighborOff)); System.arraycopy(tuple.getFieldData(0), getLeftChildPageOff(tuple) + CHILD_PTR_SIZE, buf.array(), getLeftChildPageOff(frameTuple), CHILD_PTR_SIZE); } } }
int origTupleOff = slotManager.getTupleOff(slotOff); cmpFrameTuple.resetByTupleOffset(buf.array(), origTupleOff); int cmpTupleOff = origTupleOff; slotOff += slotManager.getSlotSize(); while (slotOff < maxSlotOff) { cmpTupleOff = slotManager.getTupleOff(slotOff); frameTuple.resetByTupleOffset(buf.array(), cmpTupleOff); if (targetCmp.compare(cmpFrameTuple, frameTuple) != 0) { frameTuple.resetByTupleOffset(buf.array(), slotManager.getTupleOff(slotOff)); int childPageOff = getLeftChildPageOff(frameTuple);
int tupleOff = slotManager.getTupleOff(slotManager.getSlotEndOff()); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int splitKeySize = tupleWriter.bytesRequired(frameTuple, 0, cmp.getKeyFieldCount()); splitKey.getTuple().resetByTupleOffset(splitKey.getBuffer().array(), 0); int deleteTupleOff = slotManager.getTupleOff(slotManager.getSlotEndOff()); frameTuple.resetByTupleOffset(buf.array(), deleteTupleOff); buf.putInt(RIGHT_LEAF_OFFSET, buf.getInt(getLeftChildPageOff(frameTuple)));
int tupleOff = slotManager.getTupleOff(slotManager.getSlotEndOff()); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int splitKeySize = tupleWriter.bytesRequired(frameTuple, 0, cmp.getKeyFieldCount());
int tupleOff = slotManager.getTupleOff(slotManager.getSlotEndOff()); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int splitKeySize = tupleWriter.bytesRequired(frameTuple, 0, keyValueProviders.length);
int tupleOff = slotManager.getTupleOff(slotManager.getSlotEndOff()); frameTuple.resetByTupleOffset(buf.array(), tupleOff); int splitKeySize = tupleWriter.bytesRequired(frameTuple, 0, keyValueProviders.length);