lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r931327 - in /lucene/dev/trunk/lucene/src: java/org/apache/lucene/util/packed/Packed32.java java/org/apache/lucene/util/packed/Packed64.java test/org/apache/lucene/util/packed/TestPackedInts.java
Date Tue, 06 Apr 2010 20:58:23 GMT
Author: mikemccand
Date: Tue Apr  6 20:58:22 2010
New Revision: 931327

URL: http://svn.apache.org/viewvc?rev=931327&view=rev
Log:
LUCENE-1990: fix Mutable case where out-of-order writes could incorrectly overwrite adjacent
values

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed32.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed64.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed32.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed32.java?rev=931327&r1=931326&r2=931327&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed32.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed32.java Tue Apr 
6 20:58:22 2010
@@ -88,9 +88,14 @@ class Packed32 extends PackedInts.Reader
         currentMasks[base  ] =~((elementPosMask
                 << currentShifts[base + 1])
                 >>> currentShifts[base]);
-        currentMasks[base+1] = ~(elementPosMask
-                << currentShifts[base + 2]);
-        currentMasks[base+2] = currentShifts[base + 2] == 0 ? 0 : ~0;
+        if (bitPos <= BLOCK_SIZE - elementBits) { // Second block not used
+          currentMasks[base+1] = ~0; // Keep all bits
+          currentMasks[base+2] = 0;  // Or with 0
+        } else {
+          currentMasks[base+1] = ~(elementPosMask
+                                   << currentShifts[base + 2]);
+          currentMasks[base+2] = currentShifts[base + 2] == 0 ? 0 : ~0;
+        }
       }
     }
   }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed64.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed64.java?rev=931327&r1=931326&r2=931327&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed64.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/packed/Packed64.java Tue Apr 
6 20:58:22 2010
@@ -89,9 +89,14 @@ class Packed64 extends PackedInts.Reader
               currentMasks[base  ] =~((elementPosMask
                                  << currentShifts[base + 1])
                                 >>> currentShifts[base]);
-              currentMasks[base+1] = ~(elementPosMask
-                                 << currentShifts[base + 2]);
-              currentMasks[base+2] = currentShifts[base + 2] == 0 ? 0 : ~0;
+              if (bitPos <= BLOCK_SIZE - elementBits) { // Second block not used
+                currentMasks[base+1] = ~0; // Keep all bits
+                currentMasks[base+2] = 0;  // Or with 0
+              } else {
+                currentMasks[base+1] = ~(elementPosMask
+                                         << currentShifts[base + 2]);
+                currentMasks[base+2] = currentShifts[base + 2] == 0 ? 0 : ~0;
+              }
           }
       }
   }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java?rev=931327&r1=931326&r2=931327&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java Tue
Apr  6 20:58:22 2010
@@ -216,10 +216,18 @@ public class TestPackedInts extends Luce
     out.close();
 
     IndexInput in = dir.openInput("out");
-    PackedInts.Reader r = PackedInts.getReader(in);
+    PackedInts.getReader(in);
     assertEquals(end, in.getFilePointer());
     in.close();
 
     dir.close();
   }
+
+  public void testSecondaryBlockChange() throws IOException {
+    PackedInts.Mutable mutable = new Packed64(26, 5);
+    mutable.set(24, 31);
+    assertEquals("The value #24 should be correct", 31, mutable.get(24));
+    mutable.set(4, 16);
+    assertEquals("The value #24 should remain unchanged", 31, mutable.get(24));
+  }
 }



Mime
View raw message