You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/01/16 16:10:54 UTC
svn commit: r1059580 -
/lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/index/codecs/bulkvint/BulkVIntCodec.java
Author: rmuir
Date: Sun Jan 16 15:10:54 2011
New Revision: 1059580
URL: http://svn.apache.org/viewvc?rev=1059580&view=rev
Log:
add practical speedup/compression to bulk vint codec
Modified:
lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/index/codecs/bulkvint/BulkVIntCodec.java
Modified: lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/index/codecs/bulkvint/BulkVIntCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/index/codecs/bulkvint/BulkVIntCodec.java?rev=1059580&r1=1059579&r2=1059580&view=diff
==============================================================================
--- lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/index/codecs/bulkvint/BulkVIntCodec.java (original)
+++ lucene/dev/branches/bulkpostings/lucene/src/java/org/apache/lucene/index/codecs/bulkvint/BulkVIntCodec.java Sun Jan 16 15:10:54 2011
@@ -18,6 +18,7 @@ package org.apache.lucene.index.codecs.b
*/
import java.io.IOException;
+import java.util.Arrays;
import java.util.Set;
import org.apache.lucene.index.SegmentInfo;
@@ -83,6 +84,10 @@ public class BulkVIntCodec extends Codec
public void readBlock() throws IOException {
final int numBytes = in.readVInt(); // read header
+ if (numBytes == 0) { // 1's
+ Arrays.fill(buffer, 1);
+ return;
+ }
in.readBytes(bytes, 0, numBytes); // readBytes
int upto = 0;
@@ -113,21 +118,30 @@ public class BulkVIntCodec extends Codec
protected void flushBlock() throws IOException {
int upto = 0;
+ boolean allOnes = true;
// encode ints
for(int i=0;i<buffer.length;i++) {
int j = buffer[i];
+ if (j != 1)
+ allOnes = false;
while ((j & ~0x7F) != 0) {
bytes[upto++] = (byte)((j & 0x7f) | 0x80);
j >>>= 7;
}
bytes[upto++] = (byte)j;
}
-
- // write header (length in bytes)
- out.writeVInt(upto);
- // write block
- out.writeBytes(bytes, 0, upto);
+ if (allOnes) {
+ // the most common int pattern (all 1's)
+ // write a special header (numBytes=0) for this case.
+ out.writeVInt(0);
+ } else {
+ // write header (length in bytes)
+ out.writeVInt(upto);
+
+ // write block
+ out.writeBytes(bytes, 0, upto);
+ }
}
};
}