diff --git a/lucene/core/build.xml b/lucene/core/build.xml
index bf60a895bd8..9e2ef7499cd 100644
--- a/lucene/core/build.xml
+++ b/lucene/core/build.xml
@@ -72,6 +72,16 @@
+
+
+
+
+
+
+
+
+
diff --git a/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java b/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java
index c72683e1cf1..5cea0ff6209 100644
--- a/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java
+++ b/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java
@@ -92,58 +92,83 @@ abstract class BulkOperation implements PackedInts.Decoder, PackedInts.Encoder {
new BulkOperationPacked64(),
};
- private static final BulkOperation packedSingleBlock1 = new BulkOperationPackedSingleBlock1();
- private static final BulkOperation packedSingleBlock2 = new BulkOperationPackedSingleBlock2();
- private static final BulkOperation packedSingleBlock3 = new BulkOperationPackedSingleBlock3();
- private static final BulkOperation packedSingleBlock4 = new BulkOperationPackedSingleBlock4();
- private static final BulkOperation packedSingleBlock5 = new BulkOperationPackedSingleBlock5();
- private static final BulkOperation packedSingleBlock6 = new BulkOperationPackedSingleBlock6();
- private static final BulkOperation packedSingleBlock7 = new BulkOperationPackedSingleBlock7();
- private static final BulkOperation packedSingleBlock8 = new BulkOperationPackedSingleBlock8();
- private static final BulkOperation packedSingleBlock9 = new BulkOperationPackedSingleBlock9();
- private static final BulkOperation packedSingleBlock10 = new BulkOperationPackedSingleBlock10();
- private static final BulkOperation packedSingleBlock12 = new BulkOperationPackedSingleBlock12();
- private static final BulkOperation packedSingleBlock16 = new BulkOperationPackedSingleBlock16();
- private static final BulkOperation packedSingleBlock21 = new BulkOperationPackedSingleBlock21();
- private static final BulkOperation packedSingleBlock32 = new BulkOperationPackedSingleBlock32();
+ // NOTE: this is sparse (some entries are null):
+ private static final BulkOperation[] packedSingleBlockBulkOps = new BulkOperation[] {
+ new BulkOperationPackedSingleBlock1(),
+ new BulkOperationPackedSingleBlock2(),
+ new BulkOperationPackedSingleBlock3(),
+ new BulkOperationPackedSingleBlock4(),
+ new BulkOperationPackedSingleBlock5(),
+ new BulkOperationPackedSingleBlock6(),
+ new BulkOperationPackedSingleBlock7(),
+ new BulkOperationPackedSingleBlock8(),
+ new BulkOperationPackedSingleBlock9(),
+ new BulkOperationPackedSingleBlock10(),
+ null,
+ new BulkOperationPackedSingleBlock12(),
+ null,
+ null,
+ null,
+ new BulkOperationPackedSingleBlock16(),
+ null,
+ null,
+ null,
+ null,
+ new BulkOperationPackedSingleBlock21(),
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ new BulkOperationPackedSingleBlock32(),
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ };
+
public static BulkOperation of(PackedInts.Format format, int bitsPerValue) {
switch (format) {
case PACKED:
+ assert packedBulkOps[bitsPerValue - 1] != null;
return packedBulkOps[bitsPerValue - 1];
case PACKED_SINGLE_BLOCK:
- switch (bitsPerValue) {
- case 1:
- return packedSingleBlock1;
- case 2:
- return packedSingleBlock2;
- case 3:
- return packedSingleBlock3;
- case 4:
- return packedSingleBlock4;
- case 5:
- return packedSingleBlock5;
- case 6:
- return packedSingleBlock6;
- case 7:
- return packedSingleBlock7;
- case 8:
- return packedSingleBlock8;
- case 9:
- return packedSingleBlock9;
- case 10:
- return packedSingleBlock10;
- case 12:
- return packedSingleBlock12;
- case 16:
- return packedSingleBlock16;
- case 21:
- return packedSingleBlock21;
- case 32:
- return packedSingleBlock32;
- default:
- throw new AssertionError();
- }
+ assert packedSingleBlockBulkOps[bitsPerValue - 1] != null;
+ return packedSingleBlockBulkOps[bitsPerValue - 1];
default:
throw new AssertionError();
}
diff --git a/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py b/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py
index 70e86f41a3c..5abbd176f3c 100644
--- a/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py
+++ b/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py
@@ -124,10 +124,17 @@ def casts(typ):
cast_end = ""
return cast_start, cast_end
+def hexNoLSuffix(n):
+ # On 32 bit Python values > (1 << 31)-1 will have L appended by hex function:
+ s = hex(n)
+ if s.endswith('L'):
+ s = s[:-1]
+ return s
+
def masks(bits):
if bits == 64:
return "", ""
- return "(", " & %sL)" %(hex((1 << bits) - 1))
+ return "(", " & %sL)" %(hexNoLSuffix((1 << bits) - 1))
def get_type(bits):
if bits == 8:
@@ -427,32 +434,35 @@ if __name__ == '__main__':
f.write(' };\n')
f.write('\n')
- for bpv in PACKED_64_SINGLE_BLOCK_BPV:
- f2 = open('BulkOperationPackedSingleBlock%d.java' % bpv, 'w')
- f2.write(HEADER)
- f2.write('''/**
+ f.write(' // NOTE: this is sparse (some entries are null):\n')
+ f.write(' private static final BulkOperation[] packedSingleBlockBulkOps = new BulkOperation[] {\n')
+ for bpv in xrange(1, 65):
+ if bpv in PACKED_64_SINGLE_BLOCK_BPV:
+ f2 = open('BulkOperationPackedSingleBlock%d.java' % bpv, 'w')
+ f2.write(HEADER)
+ f2.write('''/**
* Efficient sequential read/write of packed integers.
*/\n''')
- f2.write('final class BulkOperationPackedSingleBlock%d extends BulkOperation {\n' % bpv)
- packed64singleblock(bpv,f2)
- f2.write('}\n')
- f2.close()
- f.write(' private static final BulkOperation packedSingleBlock%d = new BulkOperationPackedSingleBlock%d();\n' % (bpv, bpv))
-
+ f2.write('final class BulkOperationPackedSingleBlock%d extends BulkOperation {\n' % bpv)
+ packed64singleblock(bpv,f2)
+ f2.write('}\n')
+ f2.close()
+ f.write(' new BulkOperationPackedSingleBlock%d(),\n' % bpv)
+ else:
+ f.write(' null,\n')
+ f.write(' };\n')
+ f.write('\n')
+
f.write("\n")
f.write(" public static BulkOperation of(PackedInts.Format format, int bitsPerValue) {\n")
f.write(" switch (format) {\n")
f.write(" case PACKED:\n")
+ f.write(" assert packedBulkOps[bitsPerValue - 1] != null;\n")
f.write(" return packedBulkOps[bitsPerValue - 1];\n")
f.write(" case PACKED_SINGLE_BLOCK:\n")
- f.write(" switch (bitsPerValue) {\n")
- for i in PACKED_64_SINGLE_BLOCK_BPV:
- f.write(" case %d:\n" %i)
- f.write(" return packedSingleBlock%d;\n" %i)
- f.write(" default:\n")
- f.write(" throw new AssertionError();\n")
- f.write(" }\n")
+ f.write(" assert packedSingleBlockBulkOps[bitsPerValue - 1] != null;\n")
+ f.write(" return packedSingleBlockBulkOps[bitsPerValue - 1];\n")
f.write(" default:\n")
f.write(" throw new AssertionError();\n")
f.write(" }\n")