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/07 14:25:07 UTC

svn commit: r1370204 - /lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java

Author: mikemccand
Date: Tue Aug  7 12:25:07 2012
New Revision: 1370204

URL: http://svn.apache.org/viewvc?rev=1370204&view=rev
Log:
LUCENE-3892: only store numBits in the block header; compute numBytes @ read time

Modified:
    lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java

Modified: lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java?rev=1370204&r1=1370203&r2=1370204&view=diff
==============================================================================
--- lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java (original)
+++ lucene/dev/branches/pforcodec_3892/lucene/core/src/java/org/apache/lucene/codecs/block/ForUtil.java Tue Aug  7 12:25:07 2012
@@ -37,21 +37,19 @@ public final class ForUtil {
    *
    * @param data        uncompressed data
    * @param intBuffer   integer buffer to hold compressed data
-   * @return the header for current block 
+   * @return the number of frame bits for current block 
    */
-  public static int compress(final int[] data, IntBuffer intBuffer) {
+  static int compress(final int[] data, IntBuffer intBuffer) {
     int numBits = getNumBits(data);
     if (numBits == 0) {
       return compressDuplicateBlock(data, intBuffer);
     }
  
-    int encodedSize = (blockSize*numBits+31)/32;
-
     for (int i=0; i<blockSize; ++i) {
       encodeNormalValue(intBuffer, i, data[i], numBits);
     }
 
-    return getHeader(encodedSize, numBits);
+    return numBits;
   }
 
   /**
@@ -59,7 +57,7 @@ public final class ForUtil {
    */
   static int compressDuplicateBlock(final int[] data, IntBuffer intBuffer) {
     intBuffer.put(0, data[0]);
-    return getHeader(1, 0);
+    return 0;
   }
 
   /** Decompress given Integer buffer into int array.
@@ -68,13 +66,13 @@ public final class ForUtil {
    * @param data        int array to hold uncompressed data
    * @param header      header of current block, which contains numFrameBits
    */
-  public static void decompress(IntBuffer intBuffer, int[] data, int header) {
+  static void decompress(IntBuffer intBuffer, int[] data, int numBits) {
     // since this buffer is reused at upper level, rewind first
     intBuffer.rewind();
 
     // nocommit assert header isn't "malformed", ie besides
     // numBytes / bit-width there is nothing else!
-    decompressCore(intBuffer, data, getNumBits(header));
+    decompressCore(intBuffer, data, numBits);
   }
 
   static void decompressCore(IntBuffer intBuffer, int[] data, int numBits) {
@@ -165,23 +163,9 @@ public final class ForUtil {
   }
 
   /** 
-   * Generate the 4 byte header, which contains (from lsb to msb):
-   *
-   * 6 bits for num of frame bits (when 0, values in this block are all the same)
-   * other bits for encoded block int size (excluded header), so we can use crazy block size
-   *
-   */
-  static int getHeader(int encodedSize, int numBits) {
-    return numBits | (encodedSize << 6);
-  }
-
-  /** 
-   * Expert: get metadata from header. 
+   * Expert: get compressed block size(in byte)  
    */
-  static int getNumBits(int header) {
-    return ((header & MASK[6]));
-  }
-  static int getEncodedSize(int header) {
-    return ((header >>> 6))*4;
+  static int getEncodedSize(int numBits) {
+    return numBits == 0 ? 4 : numBits*blockSize/8;
   }
 }