Skip to content

Commit

Permalink
Add recordValueNullOffset to simplify reading TypedKeyValueHeap code
Browse files Browse the repository at this point in the history
  • Loading branch information
dain authored and wendigo committed Feb 1, 2024
1 parent d611e76 commit ef58dc5
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class TypedKeyValueHeap
private final Type valueType;
private final int capacity;

private final int recordValueNullOffset;
private final int recordKeyOffset;
private final int recordValueOffset;

Expand Down Expand Up @@ -100,7 +101,8 @@ public TypedKeyValueHeap(
boolean variableWidth = keyVariableWidth || valueVariableWidth;
variableWidthData = variableWidth ? new VariableWidthData() : null;

recordKeyOffset = (variableWidth ? POINTER_SIZE : 0) + 1;
recordValueNullOffset = (variableWidth ? POINTER_SIZE : 0);
recordKeyOffset = recordValueNullOffset + 1;
recordValueOffset = recordKeyOffset + keyType.getFlatFixedSize();
recordSize = recordValueOffset + valueType.getFlatFixedSize();

Expand All @@ -125,6 +127,7 @@ public TypedKeyValueHeap(TypedKeyValueHeap typedHeap)
this.keyVariableWidth = typedHeap.keyVariableWidth;
this.valueVariableWidth = typedHeap.valueVariableWidth;

this.recordValueNullOffset = typedHeap.recordValueNullOffset;
this.recordKeyOffset = typedHeap.recordKeyOffset;
this.recordValueOffset = typedHeap.recordValueOffset;
this.recordSize = typedHeap.recordSize;
Expand Down Expand Up @@ -208,7 +211,7 @@ private void write(int index, @Nullable BlockBuilder keyBlockBuilder, BlockBuild
throw new RuntimeException(throwable);
}
}
if (fixedChunk[recordOffset + recordKeyOffset - 1] != 0) {
if (fixedChunk[recordOffset + recordValueNullOffset] != 0) {
valueBlockBuilder.appendNull();
}
else {
Expand Down Expand Up @@ -260,7 +263,7 @@ private void clear(int index)
positionCount,
(fixedSizeOffset, variableWidthChunk, variableWidthChunkOffset) -> {
int keyVariableWidth = keyType.relocateFlatVariableWidthOffsets(fixedChunk, fixedSizeOffset + recordKeyOffset, variableWidthChunk, variableWidthChunkOffset);
if (fixedChunk[fixedSizeOffset + recordKeyOffset - 1] == 0) {
if (fixedChunk[fixedSizeOffset + recordValueNullOffset] == 0) {
valueType.relocateFlatVariableWidthOffsets(fixedChunk, fixedSizeOffset + recordValueOffset, variableWidthChunk, variableWidthChunkOffset + keyVariableWidth);
}
});
Expand Down Expand Up @@ -290,7 +293,7 @@ private void set(int index, ValueBlock keyBlock, int keyPosition, ValueBlock val
throw new RuntimeException(throwable);
}
if (valueBlock.isNull(valuePosition)) {
fixedChunk[recordOffset + recordKeyOffset - 1] = 1;
fixedChunk[recordOffset + recordValueNullOffset] = 1;
}
else {
try {
Expand Down

0 comments on commit ef58dc5

Please sign in to comment.