Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ void update(long v) {
++numValues;
}

/** Accumulate state from another tracker. */
void update(MinMaxTracker other) {
min = Math.min(min, other.min);
max = Math.max(max, other.max);
numValues += other.numValues;
}

/** Update the required space. */
void finish() {
if (max > min) {
Expand All @@ -181,6 +188,13 @@ void nextBlock() {
private long[] writeValues(FieldInfo field, DocValuesProducer valuesProducer, boolean ords)
throws IOException {
SortedNumericDocValues values = valuesProducer.getSortedNumeric(field);
final long firstValue;
if (values.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
firstValue = values.nextValue();
} else {
firstValue = 0L;
}
values = valuesProducer.getSortedNumeric(field);
int numDocsWithValue = 0;
MinMaxTracker minMax = new MinMaxTracker();
MinMaxTracker blockMinMax = new MinMaxTracker();
Expand All @@ -196,14 +210,14 @@ private long[] writeValues(FieldInfo field, DocValuesProducer valuesProducer, bo
// wrong results. Since these extreme values are unlikely, we just discard
// GCD computation for them
gcd = 1;
} else if (minMax.numValues != 0) { // minValue needs to be set first
gcd = MathUtil.gcd(gcd, v - minMax.min);
} else {
gcd = MathUtil.gcd(gcd, v - firstValue);
}
}

minMax.update(v);
blockMinMax.update(v);
if (blockMinMax.numValues == NUMERIC_BLOCK_SIZE) {
minMax.update(blockMinMax);
blockMinMax.nextBlock();
}

Expand All @@ -215,6 +229,7 @@ private long[] writeValues(FieldInfo field, DocValuesProducer valuesProducer, bo
numDocsWithValue++;
}

minMax.update(blockMinMax);
minMax.finish();
blockMinMax.finish();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ public void add(long l) throws IOException {
}

private void flush() throws IOException {
if (off == 0) {
return;
}
// Avoid writing bits from values that are outside of the range we need to encode
Arrays.fill(nextValues, off, nextValues.length, 0L);
encode(nextValues, 0, nextBlocks, 0, iterations);
final int blockCount =
(int) PackedInts.Format.PACKED.byteCount(PackedInts.VERSION_CURRENT, off, bitsPerValue);
output.writeBytes(nextBlocks, blockCount);
Arrays.fill(nextValues, 0L);
off = 0;
}

Expand Down