Skip to content

Commit

Permalink
Fix auto-generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
jpountz committed Jan 13, 2025
1 parent 1514046 commit 0347729
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 51 deletions.
4 changes: 2 additions & 2 deletions lucene/core/src/generated/checksums/generateForDeltaUtil.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"lucene/core/src/java/org/apache/lucene/codecs/lucene101/ForDeltaUtil.java": "e0bf6071bcdefaa297e0bb92f79615201777652d",
"lucene/core/src/java/org/apache/lucene/codecs/lucene101/gen_ForDeltaUtil.py": "d7484ab18da33e5cb73faaf84b4e2bb832b62f9d"
"lucene/core/src/java/org/apache/lucene/codecs/lucene101/ForDeltaUtil.java": "2c6892e931dcf5fda5a9ce9c6e66fb50604bd54c",
"lucene/core/src/java/org/apache/lucene/codecs/lucene101/gen_ForDeltaUtil.py": "a4617fcd1d7ae4112bd5d3bcc7eeb840eb0fe2f6"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,6 @@
private static final int TWO_BLOCK_SIZE_FOURTHS = BLOCK_SIZE / 2;
private static final int THREE_BLOCK_SIZE_FOURTHS = 3 * BLOCK_SIZE / 4;
// IDENTITY_PLUS_ONE[i] == i+1
private static final int[] IDENTITY_PLUS_ONE = new int[ForUtil.BLOCK_SIZE];
static {
for (int i = 0; i < ForUtil.BLOCK_SIZE; ++i) {
IDENTITY_PLUS_ONE[i] = i + 1;
}
}
private static void prefixSumOfOnes(int[] arr, int base) {
System.arraycopy(IDENTITY_PLUS_ONE, 0, arr, 0, ForUtil.BLOCK_SIZE);
// This loop gets auto-vectorized
for (int i = 0; i < ForUtil.BLOCK_SIZE; ++i) {
arr[i] += base;
}
}
private static void prefixSum8(int[] arr, int base) {
// When the number of bits per value is 4 or less, we can sum up all values in a block without
// risking overflowing an 8-bits integer. This allows computing the prefix sum by summing up 4
Expand Down Expand Up @@ -224,44 +207,32 @@
private final int[] tmp = new int[BLOCK_SIZE];
/** Return the number of bits per value required to store the given array. */
int bitsRequired(int[] ints) {
int or = 0;
for (int l : ints) {
or |= l;
}
assert or != 0;
return PackedInts.bitsRequired(or);
}
/**
* Encode deltas of a strictly monotonically increasing sequence of integers. The provided {@code
* ints} are expected to be deltas between consecutive values.
*/
void encodeDeltas(int[] ints, DataOutput out) throws IOException {
if (ints[0] == 1 && PForUtil.allEqual(ints)) { // happens with very dense postings
out.writeByte((byte) 0);
} else {
int or = 0;
for (int l : ints) {
or |= l;
}
assert or != 0;
final int bitsPerValue = PackedInts.bitsRequired(or);
out.writeByte((byte) bitsPerValue);
final int primitiveSize;
if (bitsPerValue <= 3) {
primitiveSize = 8;
collapse8(ints);
} else if (bitsPerValue <= 10) {
primitiveSize = 16;
collapse16(ints);
} else {
primitiveSize = 32;
}
encode(ints, bitsPerValue, primitiveSize, out, tmp);
}
}
/** Decode deltas, compute the prefix sum and add {@code base} to all decoded ints. */
void decodeAndPrefixSum(PostingDecodingUtil pdu, int base, int[] ints) throws IOException {
final int bitsPerValue = Byte.toUnsignedInt(pdu.in.readByte());
if (bitsPerValue == 0) {
prefixSumOfOnes(ints, base);
void encodeDeltas(int bitsPerValue, int[] ints, DataOutput out) throws IOException {
final int primitiveSize;
if (bitsPerValue <= 3) {
primitiveSize = 8;
collapse8(ints);
} else if (bitsPerValue <= 10) {
primitiveSize = 16;
collapse16(ints);
} else {
decodeAndPrefixSum(bitsPerValue, pdu, base, ints);
primitiveSize = 32;
}
encode(ints, bitsPerValue, primitiveSize, out, tmp);
}
"""
Expand Down Expand Up @@ -361,6 +332,9 @@ def writeDecode(bpv, f):
f.write(' prefixSum%d(ints, base);\n' %primitive_size)
f.write(' break;\n')
f.write(' default:\n')
f.write(' if (bitsPerValue < 1 || bitsPerValue > Integer.SIZE) {\n')
f.write(' throw new IllegalStateException("Illegal number of bits per value: " + bitsPerValue);\n')
f.write(' }\n')
f.write(' decodeSlow(bitsPerValue, pdu, tmp, ints);\n')
f.write(' prefixSum32(ints, base);\n')
f.write(' break;\n')
Expand Down

0 comments on commit 0347729

Please sign in to comment.