You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/08/23 14:51:39 UTC

svn commit: r1376473 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/core/ lucene/core/build.xml lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py

Author: mikemccand
Date: Thu Aug 23 12:51:39 2012
New Revision: 1376473

URL: http://svn.apache.org/viewvc?rev=1376473&view=rev
Log:
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

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/build.xml
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py

Modified: lucene/dev/branches/branch_4x/lucene/core/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/build.xml?rev=1376473&r1=1376472&r2=1376473&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/build.xml (original)
+++ lucene/dev/branches/branch_4x/lucene/core/build.xml Thu Aug 23 12:51:39 2012
@@ -72,6 +72,16 @@
     </sequential>
   </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">
   	<createLevAutomaton n="1"/>
   	<createLevAutomaton n="2"/>

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java?rev=1376473&r1=1376472&r2=1376473&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java Thu Aug 23 12:51:39 2012
@@ -92,58 +92,83 @@ abstract class BulkOperation implements 
     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();
     }

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py?rev=1376473&r1=1376472&r2=1376473&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py Thu Aug 23 12:51:39 2012
@@ -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")