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;
|
private final int blockSize;
|
||||||
|
|
||||||
public ForFactory() {
|
public ForFactory() {
|
||||||
this.blockSize=ForPostingsFormat.DEFAULT_BLOCK_SIZE;
|
this.blockSize = ForPostingsFormat.DEFAULT_BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
|
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
|
||||||
IndexOutput out = dir.createOutput(fileName, context);
|
return new ForIndexOutput(dir.createOutput(fileName, context), blockSize);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
|
public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
|
||||||
FixedIntBlockIndexInput ret = new ForIndexInput(dir.openInput(fileName, context));
|
return new ForIndexInput(dir.openInput(fileName, context));
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrap input and output with buffer support
|
// wrap input and output with buffer support
|
||||||
|
@ -102,13 +90,15 @@ public final class ForFactory extends IntStreamFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ForIndexOutput extends FixedIntBlockIndexOutput {
|
private class ForIndexOutput extends FixedIntBlockIndexOutput {
|
||||||
private byte[] encoded;
|
private final byte[] encoded;
|
||||||
private IntBuffer encodedBuffer;
|
private final IntBuffer encodedBuffer;
|
||||||
|
|
||||||
ForIndexOutput(IndexOutput out, int blockSize) throws IOException {
|
ForIndexOutput(IndexOutput out, int blockSize) throws IOException {
|
||||||
super(out,blockSize);
|
super(out,blockSize);
|
||||||
this.encoded = new byte[blockSize*8+4];
|
this.encoded = new byte[blockSize*8+4];
|
||||||
this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
|
this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void flushBlock() throws IOException {
|
protected void flushBlock() throws IOException {
|
||||||
final int numBytes = ForUtil.compress(buffer,buffer.length,encodedBuffer);
|
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 blockSize;
|
||||||
private final int minBlockSize;
|
private final int minBlockSize;
|
||||||
private final int maxBlockSize;
|
private final int maxBlockSize;
|
||||||
protected final static int DEFAULT_BLOCK_SIZE = 128;
|
public final static int DEFAULT_BLOCK_SIZE = 128;
|
||||||
protected final static int DEFAULT_TERM_CACHED_SIZE = 1024;
|
|
||||||
|
|
||||||
public ForPostingsFormat() {
|
public ForPostingsFormat() {
|
||||||
super("For");
|
super("For");
|
||||||
|
@ -55,6 +54,7 @@ public final class ForPostingsFormat extends PostingsFormat {
|
||||||
this.minBlockSize = BlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE;
|
this.minBlockSize = BlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE;
|
||||||
this.maxBlockSize = BlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE;
|
this.maxBlockSize = BlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForPostingsFormat(int minBlockSize, int maxBlockSize) {
|
public ForPostingsFormat(int minBlockSize, int maxBlockSize) {
|
||||||
super("For");
|
super("For");
|
||||||
this.blockSize = DEFAULT_BLOCK_SIZE;
|
this.blockSize = DEFAULT_BLOCK_SIZE;
|
||||||
|
|
|
@ -45,24 +45,12 @@ public final class PForFactory extends IntStreamFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
|
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
|
||||||
IndexOutput out = dir.createOutput(fileName, context);
|
return new PForIndexOutput(dir.createOutput(fileName, context), blockSize);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
|
public IntIndexInput openInput(Directory dir, String fileName, IOContext context) throws IOException {
|
||||||
FixedIntBlockIndexInput ret = new PForIndexInput(dir.openInput(fileName, context));
|
return new PForIndexInput(dir.openInput(fileName, context));
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrap input and output with buffer support
|
// wrap input and output with buffer support
|
||||||
|
@ -102,13 +90,15 @@ public final class PForFactory extends IntStreamFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PForIndexOutput extends FixedIntBlockIndexOutput {
|
private class PForIndexOutput extends FixedIntBlockIndexOutput {
|
||||||
private byte[] encoded;
|
private final byte[] encoded;
|
||||||
private IntBuffer encodedBuffer;
|
private final IntBuffer encodedBuffer;
|
||||||
|
|
||||||
PForIndexOutput(IndexOutput out, int blockSize) throws IOException {
|
PForIndexOutput(IndexOutput out, int blockSize) throws IOException {
|
||||||
super(out,blockSize);
|
super(out,blockSize);
|
||||||
this.encoded = new byte[blockSize*8+4];
|
this.encoded = new byte[blockSize*8+4];
|
||||||
this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
|
this.encodedBuffer=ByteBuffer.wrap(encoded).asIntBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void flushBlock() throws IOException {
|
protected void flushBlock() throws IOException {
|
||||||
final int numBytes = PForUtil.compress(buffer,buffer.length,encodedBuffer);
|
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 blockSize;
|
||||||
private final int minBlockSize;
|
private final int minBlockSize;
|
||||||
private final int maxBlockSize;
|
private final int maxBlockSize;
|
||||||
protected final static int DEFAULT_BLOCK_SIZE = 128;
|
public final static int DEFAULT_BLOCK_SIZE = 128;
|
||||||
protected final static int DEFAULT_TERM_CACHED_SIZE = 1024;
|
|
||||||
|
|
||||||
public PForPostingsFormat() {
|
public PForPostingsFormat() {
|
||||||
super("PFor");
|
super("PFor");
|
||||||
|
|
Loading…
Reference in New Issue