mirror of https://github.com/apache/lucene.git
tighten up FixedIntBlockIndexInput
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/pforcodec_3892@1357217 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
21a6450e83
commit
48d2049634
|
@ -77,16 +77,14 @@ public abstract class FixedIntBlockIndexInput extends IntIndexInput {
|
||||||
|
|
||||||
private static class Reader extends IntIndexInput.Reader {
|
private static class Reader extends IntIndexInput.Reader {
|
||||||
private final IndexInput in;
|
private final IndexInput in;
|
||||||
|
|
||||||
protected final int[] pending;
|
|
||||||
int upto;
|
|
||||||
|
|
||||||
private boolean seekPending;
|
|
||||||
private long pendingFP;
|
|
||||||
private int pendingUpto;
|
|
||||||
private long lastBlockFP;
|
|
||||||
private final BlockReader blockReader;
|
private final BlockReader blockReader;
|
||||||
private final int blockSize;
|
private final int blockSize;
|
||||||
|
private final int[] pending;
|
||||||
|
|
||||||
|
private int upto;
|
||||||
|
private boolean seekPending;
|
||||||
|
private long pendingFP;
|
||||||
|
private long lastBlockFP = -1;
|
||||||
|
|
||||||
public Reader(final IndexInput in, final int[] pending, final BlockReader blockReader)
|
public Reader(final IndexInput in, final int[] pending, final BlockReader blockReader)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -98,33 +96,28 @@ public abstract class FixedIntBlockIndexInput extends IntIndexInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
void seek(final long fp, final int upto) {
|
void seek(final long fp, final int upto) {
|
||||||
|
assert upto < blockSize;
|
||||||
|
if (seekPending || fp != lastBlockFP) {
|
||||||
pendingFP = fp;
|
pendingFP = fp;
|
||||||
pendingUpto = upto;
|
|
||||||
seekPending = true;
|
seekPending = true;
|
||||||
}
|
}
|
||||||
|
this.upto = upto;
|
||||||
private void maybeSeek() throws IOException {
|
|
||||||
if (seekPending) {
|
|
||||||
if (pendingFP != lastBlockFP) {
|
|
||||||
// need new block
|
|
||||||
in.seek(pendingFP);
|
|
||||||
lastBlockFP = pendingFP;
|
|
||||||
blockReader.readBlock();
|
|
||||||
}
|
|
||||||
upto = pendingUpto;
|
|
||||||
seekPending = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int next() throws IOException {
|
public int next() throws IOException {
|
||||||
this.maybeSeek();
|
if (seekPending) {
|
||||||
if (upto == blockSize) {
|
// Seek & load new block
|
||||||
|
in.seek(pendingFP);
|
||||||
|
lastBlockFP = pendingFP;
|
||||||
|
blockReader.readBlock();
|
||||||
|
seekPending = false;
|
||||||
|
} else if (upto == blockSize) {
|
||||||
|
// Load new block
|
||||||
lastBlockFP = in.getFilePointer();
|
lastBlockFP = in.getFilePointer();
|
||||||
blockReader.readBlock();
|
blockReader.readBlock();
|
||||||
upto = 0;
|
upto = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pending[upto++];
|
return pending[upto++];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue