lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject svn commit: r1586669 - in /lucene/dev/trunk/lucene/core/src/java/org/apache/lucene: codecs/compressing/ util/ util/packed/
Date Fri, 11 Apr 2014 14:56:29 GMT
Author: jpountz
Date: Fri Apr 11 14:56:29 2014
New Revision: 1586669

URL: http://svn.apache.org/r1586669
Log:
Extract the zig-zag encoding/decoding routines we have to utility methods.

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexReader.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexWriter.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/BitUtil.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/AbstractBlockPackedWriter.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReader.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReaderIterator.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedWriter.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedReader.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedWriter.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexReader.java?rev=1586669&r1=1586668&r2=1586669&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexReader.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexReader.java
Fri Apr 11 14:56:29 2014
@@ -17,6 +17,8 @@ package org.apache.lucene.codecs.compres
  * limitations under the License.
  */
 
+import static org.apache.lucene.util.BitUtil.zigZagDecode;
+
 import java.io.IOException;
 import java.util.Arrays;
 
@@ -33,10 +35,6 @@ import org.apache.lucene.util.packed.Pac
  */
 public final class CompressingStoredFieldsIndexReader implements Cloneable {
 
-  static long moveLowOrderBitToSign(long n) {
-    return ((n >>> 1) ^ -(n & 1));
-  }
-
   final int maxDoc;
   final int[] docBases;
   final long[] startPointers;
@@ -122,13 +120,13 @@ public final class CompressingStoredFiel
 
   private int relativeDocBase(int block, int relativeChunk) {
     final int expected = avgChunkDocs[block] * relativeChunk;
-    final long delta = moveLowOrderBitToSign(docBasesDeltas[block].get(relativeChunk));
+    final long delta = zigZagDecode(docBasesDeltas[block].get(relativeChunk));
     return expected + (int) delta;
   }
 
   private long relativeStartPointer(int block, int relativeChunk) {
     final long expected = avgChunkSizes[block] * relativeChunk;
-    final long delta = moveLowOrderBitToSign(startPointersDeltas[block].get(relativeChunk));
+    final long delta = zigZagDecode(startPointersDeltas[block].get(relativeChunk));
     return expected + delta;
   }
 

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexWriter.java?rev=1586669&r1=1586668&r2=1586669&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexWriter.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsIndexWriter.java
Fri Apr 11 14:56:29 2014
@@ -17,6 +17,8 @@ package org.apache.lucene.codecs.compres
  * limitations under the License.
  */
 
+import static org.apache.lucene.util.BitUtil.zigZagEncode;
+
 import java.io.Closeable;
 import java.io.IOException;
 
@@ -72,10 +74,6 @@ public final class CompressingStoredFiel
   
   static final int BLOCK_SIZE = 1024; // number of chunks to serialize at once
 
-  static long moveSignToLowOrderBit(long n) {
-    return (n >> 63) ^ (n << 1);
-  }
-
   final IndexOutput fieldsIndexOut;
   int totalDocs;
   int blockDocs;
@@ -124,7 +122,7 @@ public final class CompressingStoredFiel
     long maxDelta = 0;
     for (int i = 0; i < blockChunks; ++i) {
       final int delta = docBase - avgChunkDocs * i;
-      maxDelta |= moveSignToLowOrderBit(delta);
+      maxDelta |= zigZagEncode(delta);
       docBase += docBaseDeltas[i];
     }
 
@@ -135,8 +133,8 @@ public final class CompressingStoredFiel
     docBase = 0;
     for (int i = 0; i < blockChunks; ++i) {
       final long delta = docBase - avgChunkDocs * i;
-      assert PackedInts.bitsRequired(moveSignToLowOrderBit(delta)) <= writer.bitsPerValue();
-      writer.add(moveSignToLowOrderBit(delta));
+      assert PackedInts.bitsRequired(zigZagEncode(delta)) <= writer.bitsPerValue();
+      writer.add(zigZagEncode(delta));
       docBase += docBaseDeltas[i];
     }
     writer.finish();
@@ -155,7 +153,7 @@ public final class CompressingStoredFiel
     for (int i = 0; i < blockChunks; ++i) {
       startPointer += startPointerDeltas[i];
       final long delta = startPointer - avgChunkSize * i;
-      maxDelta |= moveSignToLowOrderBit(delta);
+      maxDelta |= zigZagEncode(delta);
     }
 
     final int bitsPerStartPointer = PackedInts.bitsRequired(maxDelta);
@@ -166,8 +164,8 @@ public final class CompressingStoredFiel
     for (int i = 0; i < blockChunks; ++i) {
       startPointer += startPointerDeltas[i];
       final long delta = startPointer - avgChunkSize * i;
-      assert PackedInts.bitsRequired(moveSignToLowOrderBit(delta)) <= writer.bitsPerValue();
-      writer.add(moveSignToLowOrderBit(delta));
+      assert PackedInts.bitsRequired(zigZagEncode(delta)) <= writer.bitsPerValue();
+      writer.add(zigZagEncode(delta));
     }
     writer.finish();
   }

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/BitUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/BitUtil.java?rev=1586669&r1=1586668&r2=1586669&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/BitUtil.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/BitUtil.java Fri Apr 11 14:56:29
2014
@@ -187,4 +187,29 @@ public final class BitUtil {
     return v;
   }
 
+   /** Same as {@link #zigZagEncode(long)} but on integers. */
+   public static int zigZagEncode(int i) {
+     return (i >> 31) ^ (i << 1);
+   }
+
+   /**
+    * <a href="https://developers.google.com/protocol-buffers/docs/encoding#types">Zig-zag</a>
+    * encode the provided long. Assuming the input is a signed long whose
+    * absolute value can be stored on <tt>n</tt> bits, the returned value will
+    * be an unsigned long that can be stored on <tt>n+1</tt> bits.
+    */
+   public static long zigZagEncode(long l) {
+     return (l >> 63) ^ (l << 1);
+   }
+
+   /** Decode an int previously encoded with {@link #zigZagEncode(int)}. */
+   public static int zigZagDecode(int i) {
+     return ((i >>> 1) ^ -(i & 1));
+   }
+
+   /** Decode a long previously encoded with {@link #zigZagEncode(long)}. */
+   public static long zigZagDecode(long l) {
+     return ((l >>> 1) ^ -(l & 1));
+   }
+
 }

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/AbstractBlockPackedWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/AbstractBlockPackedWriter.java?rev=1586669&r1=1586668&r2=1586669&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/AbstractBlockPackedWriter.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/AbstractBlockPackedWriter.java
Fri Apr 11 14:56:29 2014
@@ -31,10 +31,6 @@ abstract class AbstractBlockPackedWriter
   static final int MIN_VALUE_EQUALS_0 = 1 << 0;
   static final int BPV_SHIFT = 1;
 
-  static long zigZagEncode(long n) {
-    return (n >> 63) ^ (n << 1);
-  }
-
   // same as DataOutput.writeVLong but accepts negative values
   static void writeVLong(DataOutput out, long i) throws IOException {
     int k = 0;

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReader.java?rev=1586669&r1=1586668&r2=1586669&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReader.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReader.java
Fri Apr 11 14:56:29 2014
@@ -17,12 +17,12 @@ package org.apache.lucene.util.packed;
  * limitations under the License.
  */
 
+import static org.apache.lucene.util.BitUtil.zigZagDecode;
 import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.BPV_SHIFT;
 import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MAX_BLOCK_SIZE;
 import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MIN_BLOCK_SIZE;
 import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MIN_VALUE_EQUALS_0;
 import static org.apache.lucene.util.packed.BlockPackedReaderIterator.readVLong;
-import static org.apache.lucene.util.packed.BlockPackedReaderIterator.zigZagDecode;
 import static org.apache.lucene.util.packed.PackedInts.checkBlockSize;
 import static org.apache.lucene.util.packed.PackedInts.numBlocks;
 

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReaderIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReaderIterator.java?rev=1586669&r1=1586668&r2=1586669&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReaderIterator.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedReaderIterator.java
Fri Apr 11 14:56:29 2014
@@ -17,6 +17,7 @@ package org.apache.lucene.util.packed;
  * limitations under the License.
  */
 
+import static org.apache.lucene.util.BitUtil.zigZagDecode;
 import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.BPV_SHIFT;
 import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MAX_BLOCK_SIZE;
 import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MIN_BLOCK_SIZE;
@@ -38,10 +39,6 @@ import org.apache.lucene.util.LongsRef;
  */
 public final class BlockPackedReaderIterator {
 
-  static long zigZagDecode(long n) {
-    return ((n >>> 1) ^ -(n & 1));
-  }
-
   // same as DataInput.readVLong but supports negative values
   static long readVLong(DataInput in) throws IOException {
     byte b = in.readByte();

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedWriter.java?rev=1586669&r1=1586668&r2=1586669&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedWriter.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BlockPackedWriter.java
Fri Apr 11 14:56:29 2014
@@ -17,6 +17,8 @@ package org.apache.lucene.util.packed;
  * limitations under the License.
  */
 
+import static org.apache.lucene.util.BitUtil.zigZagEncode;
+
 import java.io.IOException;
 
 import org.apache.lucene.store.DataOutput;

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedReader.java?rev=1586669&r1=1586668&r2=1586669&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedReader.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedReader.java
Fri Apr 11 14:56:29 2014
@@ -17,9 +17,9 @@ package org.apache.lucene.util.packed;
  * limitations under the License.
  */
 
+import static org.apache.lucene.util.BitUtil.zigZagDecode;
 import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MAX_BLOCK_SIZE;
 import static org.apache.lucene.util.packed.AbstractBlockPackedWriter.MIN_BLOCK_SIZE;
-import static org.apache.lucene.util.packed.BlockPackedReaderIterator.zigZagDecode;
 import static org.apache.lucene.util.packed.PackedInts.checkBlockSize;
 import static org.apache.lucene.util.packed.PackedInts.numBlocks;
 

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedWriter.java?rev=1586669&r1=1586668&r2=1586669&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedWriter.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/MonotonicBlockPackedWriter.java
Fri Apr 11 14:56:29 2014
@@ -17,6 +17,8 @@ package org.apache.lucene.util.packed;
  * limitations under the License.
  */
 
+import static org.apache.lucene.util.BitUtil.zigZagEncode;
+
 import java.io.IOException;
 
 import org.apache.lucene.store.DataOutput;



Mime
View raw message