LUCENE-3892: fixed extra L problem on 32 bit python; add ant target to gen bulk ops; use sparse array not switch for the single block case

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1376468 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-08-23 12:49:21 +00:00
parent 580c92a55a
commit b02c7581fc
3 changed files with 109 additions and 64 deletions

View File

@ -72,6 +72,16 @@
</sequential> </sequential>
</macrodef> </macrodef>
<target name="createBulkPackedIntSources">
<sequential>
<exec dir="src/java/org/apache/lucene/util/packed"
executable="${python.exe}" failonerror="true">
<arg line="gen_BulkOperation.py"/>
</exec>
<fixcrlf srcdir="src/java/org/apache/lucene/util/packed" includes="BulkOperation*.java" encoding="UTF-8"/>
</sequential>
</target>
<target name="createLevAutomata" depends="check-moman,clone-moman,pull-moman"> <target name="createLevAutomata" depends="check-moman,clone-moman,pull-moman">
<createLevAutomaton n="1"/> <createLevAutomaton n="1"/>
<createLevAutomaton n="2"/> <createLevAutomaton n="2"/>

View File

@ -92,58 +92,83 @@ abstract class BulkOperation implements PackedInts.Decoder, PackedInts.Encoder {
new BulkOperationPacked64(), new BulkOperationPacked64(),
}; };
private static final BulkOperation packedSingleBlock1 = new BulkOperationPackedSingleBlock1(); // NOTE: this is sparse (some entries are null):
private static final BulkOperation packedSingleBlock2 = new BulkOperationPackedSingleBlock2(); private static final BulkOperation[] packedSingleBlockBulkOps = new BulkOperation[] {
private static final BulkOperation packedSingleBlock3 = new BulkOperationPackedSingleBlock3(); new BulkOperationPackedSingleBlock1(),
private static final BulkOperation packedSingleBlock4 = new BulkOperationPackedSingleBlock4(); new BulkOperationPackedSingleBlock2(),
private static final BulkOperation packedSingleBlock5 = new BulkOperationPackedSingleBlock5(); new BulkOperationPackedSingleBlock3(),
private static final BulkOperation packedSingleBlock6 = new BulkOperationPackedSingleBlock6(); new BulkOperationPackedSingleBlock4(),
private static final BulkOperation packedSingleBlock7 = new BulkOperationPackedSingleBlock7(); new BulkOperationPackedSingleBlock5(),
private static final BulkOperation packedSingleBlock8 = new BulkOperationPackedSingleBlock8(); new BulkOperationPackedSingleBlock6(),
private static final BulkOperation packedSingleBlock9 = new BulkOperationPackedSingleBlock9(); new BulkOperationPackedSingleBlock7(),
private static final BulkOperation packedSingleBlock10 = new BulkOperationPackedSingleBlock10(); new BulkOperationPackedSingleBlock8(),
private static final BulkOperation packedSingleBlock12 = new BulkOperationPackedSingleBlock12(); new BulkOperationPackedSingleBlock9(),
private static final BulkOperation packedSingleBlock16 = new BulkOperationPackedSingleBlock16(); new BulkOperationPackedSingleBlock10(),
private static final BulkOperation packedSingleBlock21 = new BulkOperationPackedSingleBlock21(); null,
private static final BulkOperation packedSingleBlock32 = new BulkOperationPackedSingleBlock32(); 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) { public static BulkOperation of(PackedInts.Format format, int bitsPerValue) {
switch (format) { switch (format) {
case PACKED: case PACKED:
assert packedBulkOps[bitsPerValue - 1] != null;
return packedBulkOps[bitsPerValue - 1]; return packedBulkOps[bitsPerValue - 1];
case PACKED_SINGLE_BLOCK: case PACKED_SINGLE_BLOCK:
switch (bitsPerValue) { assert packedSingleBlockBulkOps[bitsPerValue - 1] != null;
case 1: return packedSingleBlockBulkOps[bitsPerValue - 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();
}
default: default:
throw new AssertionError(); throw new AssertionError();
} }

View File

@ -124,10 +124,17 @@ def casts(typ):
cast_end = "" cast_end = ""
return cast_start, 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): def masks(bits):
if bits == 64: if bits == 64:
return "", "" return "", ""
return "(", " & %sL)" %(hex((1 << bits) - 1)) return "(", " & %sL)" %(hexNoLSuffix((1 << bits) - 1))
def get_type(bits): def get_type(bits):
if bits == 8: if bits == 8:
@ -427,32 +434,35 @@ if __name__ == '__main__':
f.write(' };\n') f.write(' };\n')
f.write('\n') f.write('\n')
for bpv in PACKED_64_SINGLE_BLOCK_BPV: f.write(' // NOTE: this is sparse (some entries are null):\n')
f2 = open('BulkOperationPackedSingleBlock%d.java' % bpv, 'w') f.write(' private static final BulkOperation[] packedSingleBlockBulkOps = new BulkOperation[] {\n')
f2.write(HEADER) for bpv in xrange(1, 65):
f2.write('''/** 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. * Efficient sequential read/write of packed integers.
*/\n''') */\n''')
f2.write('final class BulkOperationPackedSingleBlock%d extends BulkOperation {\n' % bpv) f2.write('final class BulkOperationPackedSingleBlock%d extends BulkOperation {\n' % bpv)
packed64singleblock(bpv,f2) packed64singleblock(bpv,f2)
f2.write('}\n') f2.write('}\n')
f2.close() f2.close()
f.write(' private static final BulkOperation packedSingleBlock%d = new BulkOperationPackedSingleBlock%d();\n' % (bpv, bpv)) f.write(' new BulkOperationPackedSingleBlock%d(),\n' % bpv)
else:
f.write(' null,\n')
f.write(' };\n')
f.write('\n')
f.write("\n") f.write("\n")
f.write(" public static BulkOperation of(PackedInts.Format format, int bitsPerValue) {\n") f.write(" public static BulkOperation of(PackedInts.Format format, int bitsPerValue) {\n")
f.write(" switch (format) {\n") f.write(" switch (format) {\n")
f.write(" case PACKED:\n") f.write(" case PACKED:\n")
f.write(" assert packedBulkOps[bitsPerValue - 1] != null;\n")
f.write(" return packedBulkOps[bitsPerValue - 1];\n") f.write(" return packedBulkOps[bitsPerValue - 1];\n")
f.write(" case PACKED_SINGLE_BLOCK:\n") f.write(" case PACKED_SINGLE_BLOCK:\n")
f.write(" switch (bitsPerValue) {\n") f.write(" assert packedSingleBlockBulkOps[bitsPerValue - 1] != null;\n")
for i in PACKED_64_SINGLE_BLOCK_BPV: f.write(" return packedSingleBlockBulkOps[bitsPerValue - 1];\n")
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(" default:\n") f.write(" default:\n")
f.write(" throw new AssertionError();\n") f.write(" throw new AssertionError();\n")
f.write(" }\n") f.write(" }\n")