mirror of https://github.com/apache/lucene.git
LUCENE-3892: small cleanups to For/PFor postings formats
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/pforcodec_3892@1357349 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0c670cbf4b
commit
3fb11c875d
|
@ -40,29 +40,17 @@ public final class ForFactory extends IntStreamFactory {
|
|||
private final int blockSize;
|
||||
|
||||
public ForFactory() {
|
||||
this.blockSize=ForPostingsFormat.DEFAULT_BLOCK_SIZE;
|
||||
this.blockSize = ForPostingsFormat.DEFAULT_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
|
||||
IndexOutput out = dir.createOutput(fileName, context);
|
||||
boolean success = false;
|
||||
try {
|
||||
FixedIntBlockIndexOutput ret = new ForIndexOutput(out, blockSize);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
if (!success) {
|
||||
// TODO: why handle exception like this?
|
||||
// and why not use similar codes for read part?
|
||||
IOUtils.closeWhileHandlingException(out);
|
||||
}
|
||||
}
|
||||
return new ForIndexOutput(dir.createOutput(fileName, context), blockSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
|
||||
FixedIntBlockIndexInput ret = new ForIndexInput(dir.openInput(fileName, context));
|
||||
return ret;
|
||||
return new ForIndexInput(dir.openInput(fileName, context));
|
||||
}
|
||||
|
||||
// wrap input and output with buffer support
|
||||
|
@ -102,13 +90,15 @@ public final class ForFactory extends IntStreamFactory {
|
|||
}
|
||||
|
||||
private class ForIndexOutput extends FixedIntBlockIndexOutput {
|
||||
private byte[] encoded;
|
||||
private IntBuffer encodedBuffer;
|
||||
private final byte[] encoded;
|
||||
private final IntBuffer encodedBuffer;
|
||||
|
||||
ForIndexOutput(IndexOutput out, int blockSize) throws IOException {
|
||||
super(out,blockSize);
|
||||
this.encoded = new byte[blockSize*8+4];
|
||||
this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void flushBlock() throws IOException {
|
||||
final int numBytes = ForUtil.compress(buffer,buffer.length,encodedBuffer);
|
||||
|
|
|
@ -46,8 +46,7 @@ public final class ForPostingsFormat extends PostingsFormat {
|
|||
private final int blockSize;
|
||||
private final int minBlockSize;
|
||||
private final int maxBlockSize;
|
||||
protected final static int DEFAULT_BLOCK_SIZE = 128;
|
||||
protected final static int DEFAULT_TERM_CACHED_SIZE = 1024;
|
||||
public final static int DEFAULT_BLOCK_SIZE = 128;
|
||||
|
||||
public ForPostingsFormat() {
|
||||
super("For");
|
||||
|
@ -55,6 +54,7 @@ public final class ForPostingsFormat extends PostingsFormat {
|
|||
this.minBlockSize = BlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE;
|
||||
this.maxBlockSize = BlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
public ForPostingsFormat(int minBlockSize, int maxBlockSize) {
|
||||
super("For");
|
||||
this.blockSize = DEFAULT_BLOCK_SIZE;
|
||||
|
|
|
@ -45,24 +45,12 @@ public final class PForFactory extends IntStreamFactory {
|
|||
|
||||
@Override
|
||||
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
|
||||
IndexOutput out = dir.createOutput(fileName, context);
|
||||
boolean success = false;
|
||||
try {
|
||||
FixedIntBlockIndexOutput ret = new PForIndexOutput(out, blockSize);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
if (!success) {
|
||||
// TODO: why handle exception like this?
|
||||
// and why not use similar codes for read part?
|
||||
IOUtils.closeWhileHandlingException(out);
|
||||
}
|
||||
}
|
||||
return new PForIndexOutput(dir.createOutput(fileName, context), blockSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
|
||||
FixedIntBlockIndexInput ret = new PForIndexInput(dir.openInput(fileName, context));
|
||||
return ret;
|
||||
return new PForIndexInput(dir.openInput(fileName, context));
|
||||
}
|
||||
|
||||
// wrap input and output with buffer support
|
||||
|
@ -102,13 +90,15 @@ public final class PForFactory extends IntStreamFactory {
|
|||
}
|
||||
|
||||
private class PForIndexOutput extends FixedIntBlockIndexOutput {
|
||||
private byte[] encoded;
|
||||
private IntBuffer encodedBuffer;
|
||||
private final byte[] encoded;
|
||||
private final IntBuffer encodedBuffer;
|
||||
|
||||
PForIndexOutput(IndexOutput out, int blockSize) throws IOException {
|
||||
super(out,blockSize);
|
||||
this.encoded = new byte[blockSize*8+4];
|
||||
this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void flushBlock() throws IOException {
|
||||
final int numBytes = PForUtil.compress(buffer,buffer.length,encodedBuffer);
|
||||
|
|
|
@ -46,8 +46,7 @@ public final class PForPostingsFormat extends PostingsFormat {
|
|||
private final int blockSize;
|
||||
private final int minBlockSize;
|
||||
private final int maxBlockSize;
|
||||
protected final static int DEFAULT_BLOCK_SIZE = 128;
|
||||
protected final static int DEFAULT_TERM_CACHED_SIZE = 1024;
|
||||
public final static int DEFAULT_BLOCK_SIZE = 128;
|
||||
|
||||
public PForPostingsFormat() {
|
||||
super("PFor");
|
||||
|
|
Loading…
Reference in New Issue