add in-ram datastructure to Numeric codec api too

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1411200 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-11-19 14:29:53 +00:00
parent fef8857bd7
commit 898ae3f93b
2 changed files with 43 additions and 1 deletions

View File

@ -85,7 +85,7 @@ public abstract class SimpleDVConsumer implements Closeable {
//System.out.println("merge field=" + mergeState.fieldInfo.name);
NumericDocValues docValues = reader.getNumericDocValues(mergeState.fieldInfo.name);
if (docValues == null) {
docValues = new NumericDocValues.EMPTY(1);
docValues = new NumericDocValues.EMPTY(maxDoc);
}
for (int i = 0; i < maxDoc; i++) {
if (liveDocs == null || liveDocs.get(i)) {

View File

@ -25,6 +25,48 @@ public abstract class NumericDocValues {
public abstract long minValue();
public abstract long maxValue();
public abstract int size();
public NumericDocValues newRAMInstance() {
// TODO: optimize this default impl with e.g. isFixedLength/maxLength and so on
// nocommit used packed ints/pagedbytes and so on
final int maxDoc = size();
final long minValue = minValue();
final long maxValue = maxValue();
final long[] values = new long[maxDoc];
for(int docID=0;docID<maxDoc;docID++) {
values[docID] = get(docID);
}
return new NumericDocValues() {
@Override
public long get(int docID) {
return values[docID];
}
@Override
public int size() {
return maxDoc;
}
@Override
public long minValue() {
return minValue;
}
@Override
public long maxValue() {
return maxValue;
}
@Override
public NumericDocValues newRAMInstance() {
// nocommit: ugly, maybe throw exception instead?
return this;
}
};
}
public static final class EMPTY extends NumericDocValues {
private final int size;