Skip to content

Commit

Permalink
Use Ryan's formulation of fillChunk.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpwright committed Nov 21, 2024
1 parent d432b0a commit 3ecc9b6
Showing 1 changed file with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,34 +281,20 @@ private void doFill(@NotNull final RowSequence rowSequence, final WritableChunk<

int offset = 0;

try (final RowSet.Iterator inputRows = inputRowSet.iterator();
try (final RowSequence.Iterator inputRows = inputRowSet.getRowSequenceIterator();
final RowSet.Iterator trueRows = filtered.iterator()) {
long nextTrue = trueRows.hasNext() ? trueRows.nextLong() : -1;
while (nextTrue >= 0) {
// the input iterator is a superset of the true iterator, so we can always find out what
// the next value is without needing to check hasNext
final long nextInput = inputRows.nextLong();
final boolean found = nextInput == nextTrue;
booleanDestination.set(offset++, found);
if (found) {
nextTrue = trueRows.hasNext() ? trueRows.nextLong() : -1;
while (trueRows.hasNext()) {
final long nextTrue = trueRows.nextLong();
// Find all the false rows between the last consumed input row and the next true row
final int falsesSkipped = (int) inputRows.advanceAndGetPositionDistance(nextTrue + 1) - 1;
if (falsesSkipped > 0) {
booleanDestination.fillWithValue(offset, falsesSkipped, false);
offset += falsesSkipped;
}
booleanDestination.set(offset++, true);
}
}

/*
* This alternative formulation from Ryan is fairly close in terms of performance. It might be very
* slightly worse on the dense cases, and slightly better on the sparse cases.
*/
/*
* try (final RowSequence.Iterator inputRows = inputRowSet.getRowSequenceIterator(); final
* RowSet.Iterator trueRows = filtered.iterator()) { while (trueRows.hasNext()) { final long nextTrue =
* trueRows.nextLong(); // Find all the false rows between the last consumed input row and the next true
* row final int falsesSkipped = (int) inputRows.advanceAndGetPositionDistance(nextTrue + 1) - 1; if
* (falsesSkipped > 0) { booleanDestination.fillWithValue(offset, falsesSkipped, false); offset +=
* falsesSkipped; } booleanDestination.set(offset++, true); } }
*/

final int remainingFalses = booleanDestination.size() - offset;
// Fill everything else up with false, because we've exhausted the trues
if (remainingFalses > 0) {
Expand Down

0 comments on commit 3ecc9b6

Please sign in to comment.