Index: lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexInput.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexInput.java (revision 1069843) +++ lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexInput.java (working copy) @@ -157,17 +157,17 @@ @Override public void read(final DataInput indexIn, final boolean absolute) throws IOException { if (absolute) { + upto = indexIn.readVInt(); fp = indexIn.readVLong(); - upto = indexIn.readByte()&0xFF; } else { - final long delta = indexIn.readVLong(); - if (delta == 0) { + final int uptoDelta = indexIn.readVInt(); + if ((uptoDelta & 1) == 1) { // same block - upto = indexIn.readByte()&0xFF; + upto += uptoDelta >>> 1; } else { // new block - fp += delta; - upto = indexIn.readByte()&0xFF; + upto = uptoDelta >>> 1; + fp += indexIn.readVLong(); } } // TODO: we can't do this assert because non-causal Index: lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexOutput.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexOutput.java (revision 1069843) +++ lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexOutput.java (working copy) @@ -42,16 +42,14 @@ private int upto; - private static final int MAX_BLOCK_SIZE = 1 << 8; + // TODO what Var-Var codecs exist in practice... and what are there blocksizes like? + // if its less than 128 we should set that as max and use byte? - /** NOTE: maxBlockSize plus the max non-causal lookahead - * of your codec must be less than 256. EG Simple9 + /** NOTE: maxBlockSize must be the maximum block size + * plus the max non-causal lookahead of your codec. EG Simple9 * requires lookahead=1 because on seeing the Nth value * it knows it must now encode the N-1 values before it. */ protected VariableIntBlockIndexOutput(IndexOutput out, int maxBlockSize) throws IOException { - if (maxBlockSize > MAX_BLOCK_SIZE) { - throw new IllegalArgumentException("maxBlockSize must be <= " + MAX_BLOCK_SIZE + "; got " + maxBlockSize); - } this.out = out; out.writeInt(maxBlockSize); } @@ -88,17 +86,17 @@ public void write(IndexOutput indexOut, boolean absolute) throws IOException { assert upto >= 0; if (absolute) { + indexOut.writeVInt(upto); indexOut.writeVLong(fp); - indexOut.writeByte((byte) upto); } else if (fp == lastFP) { // same block - indexOut.writeVLong(0); assert upto >= lastUpto; - indexOut.writeByte((byte) upto); + int uptoDelta = upto - lastUpto; + indexOut.writeVInt(uptoDelta << 1 | 1); } else { // new block + indexOut.writeVInt(upto << 1); indexOut.writeVLong(fp - lastFP); - indexOut.writeByte((byte) upto); } lastUpto = upto; lastFP = fp; Index: lucene/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexInput.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexInput.java (revision 1069843) +++ lucene/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexInput.java (working copy) @@ -144,19 +144,17 @@ // nocommit -- somehow we should share the "upto" for // doc & freq since they will always be "in sync" if (absolute) { - fp = indexIn.readVLong(); upto = indexIn.readVInt(); + fp = indexIn.readVLong(); } else { - // nocommit -- can't this be more efficient? read a - // single byte and check a bit? block size is 128... - final long delta = indexIn.readVLong(); - if (delta == 0) { + final int uptoDelta = indexIn.readVInt(); + if ((uptoDelta & 1) == 1) { // same block - upto += indexIn.readVInt(); + upto += uptoDelta >>> 1; } else { // new block - fp += delta; - upto = indexIn.readVInt(); + upto = uptoDelta >>> 1; + fp += indexIn.readVLong(); } } assert upto < blockSize; Index: lucene/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java =================================================================== --- lucene/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java (revision 1069843) +++ lucene/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java (working copy) @@ -77,17 +77,17 @@ @Override public void write(IndexOutput indexOut, boolean absolute) throws IOException { if (absolute) { + indexOut.writeVInt(upto); indexOut.writeVLong(fp); - indexOut.writeVInt(upto); } else if (fp == lastFP) { // same block - indexOut.writeVLong(0); assert upto >= lastUpto; - indexOut.writeVInt(upto - lastUpto); + int uptoDelta = upto - lastUpto; + indexOut.writeVInt(uptoDelta << 1 | 1); } else { // new block + indexOut.writeVInt(upto << 1); indexOut.writeVLong(fp - lastFP); - indexOut.writeVInt(upto); } lastUpto = upto; lastFP = fp;