move datastructures for numerics back to codec

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

View File

@ -400,19 +400,21 @@ class FieldCacheImpl implements FieldCache {
protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField) protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException { throws IOException {
int maxDoc = reader.maxDoc();
final byte[] values;
NumericDocValues valuesIn = reader.getNumericDocValues(key.field); NumericDocValues valuesIn = reader.getNumericDocValues(key.field);
if (valuesIn != null) { if (valuesIn != null) {
final NumericDocValues ramInstance = valuesIn.newRAMInstance();
return new Bytes() {
@Override
public byte get(int docID) {
return (byte) ramInstance.get(docID);
}
};
// nocommit should we throw exc if parser isn't // nocommit should we throw exc if parser isn't
// null? if setDocsWithField is true? // null? if setDocsWithField is true?
values = new byte[maxDoc];
for(int docID=0;docID<maxDoc;docID++) {
values[docID] = (byte) valuesIn.get(docID);
}
} else { } else {
int maxDoc = reader.maxDoc();
final byte[] values;
final ByteParser parser = (ByteParser) key.custom; final ByteParser parser = (ByteParser) key.custom;
if (parser == null) { if (parser == null) {
// Confusing: must delegate to wrapper (vs simply // Confusing: must delegate to wrapper (vs simply
@ -442,11 +444,11 @@ class FieldCacheImpl implements FieldCache {
if (setDocsWithField) { if (setDocsWithField) {
wrapper.setDocsWithField(reader, key.field, u.docsWithField); wrapper.setDocsWithField(reader, key.field, u.docsWithField);
} }
}
return new BytesFromArray(values); return new BytesFromArray(values);
} }
} }
}
// inherit javadocs // inherit javadocs
public Shorts getShorts (AtomicReader reader, String field, boolean setDocsWithField) throws IOException { public Shorts getShorts (AtomicReader reader, String field, boolean setDocsWithField) throws IOException {
@ -482,18 +484,20 @@ class FieldCacheImpl implements FieldCache {
protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField) protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException { throws IOException {
int maxDoc = reader.maxDoc();
final short[] values;
NumericDocValues valuesIn = reader.getNumericDocValues(key.field); NumericDocValues valuesIn = reader.getNumericDocValues(key.field);
if (valuesIn != null) { if (valuesIn != null) {
final NumericDocValues ramInstance = valuesIn.newRAMInstance();
return new Shorts() {
@Override
public short get(int docID) {
return (short) ramInstance.get(docID);
}
};
// nocommit should we throw exc if parser isn't // nocommit should we throw exc if parser isn't
// null? if setDocsWithField is true? // null? if setDocsWithField is true?
values = new short[maxDoc];
for(int docID=0;docID<maxDoc;docID++) {
values[docID] = (short) valuesIn.get(docID);
}
} else { } else {
int maxDoc = reader.maxDoc();
final short[] values;
final ShortParser parser = (ShortParser) key.custom; final ShortParser parser = (ShortParser) key.custom;
if (parser == null) { if (parser == null) {
// Confusing: must delegate to wrapper (vs simply // Confusing: must delegate to wrapper (vs simply
@ -522,10 +526,10 @@ class FieldCacheImpl implements FieldCache {
if (setDocsWithField) { if (setDocsWithField) {
wrapper.setDocsWithField(reader, key.field, u.docsWithField); wrapper.setDocsWithField(reader, key.field, u.docsWithField);
} }
}
return new ShortsFromArray(values); return new ShortsFromArray(values);
} }
} }
}
// inherit javadocs // inherit javadocs
public Ints getInts (AtomicReader reader, String field, boolean setDocsWithField) throws IOException { public Ints getInts (AtomicReader reader, String field, boolean setDocsWithField) throws IOException {
@ -561,18 +565,20 @@ class FieldCacheImpl implements FieldCache {
protected Object createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField) protected Object createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException { throws IOException {
int maxDoc = reader.maxDoc();
final int[] values;
NumericDocValues valuesIn = reader.getNumericDocValues(key.field); NumericDocValues valuesIn = reader.getNumericDocValues(key.field);
if (valuesIn != null) { if (valuesIn != null) {
final NumericDocValues ramInstance = valuesIn.newRAMInstance();
return new Ints() {
@Override
public int get(int docID) {
return (int) ramInstance.get(docID);
}
};
// nocommit should we throw exc if parser isn't // nocommit should we throw exc if parser isn't
// null? if setDocsWithField is true? // null? if setDocsWithField is true?
values = new int[maxDoc];
for(int docID=0;docID<maxDoc;docID++) {
values[docID] = (int) valuesIn.get(docID);
}
} else { } else {
int maxDoc = reader.maxDoc();
final int[] values;
final IntParser parser = (IntParser) key.custom; final IntParser parser = (IntParser) key.custom;
if (parser == null) { if (parser == null) {
// Confusing: must delegate to wrapper (vs simply // Confusing: must delegate to wrapper (vs simply
@ -610,10 +616,10 @@ class FieldCacheImpl implements FieldCache {
if (setDocsWithField) { if (setDocsWithField) {
wrapper.setDocsWithField(reader, key.field, u.docsWithField); wrapper.setDocsWithField(reader, key.field, u.docsWithField);
} }
}
return new IntsFromArray(values); return new IntsFromArray(values);
} }
} }
}
// nocommit must advertise that this does NOT work if you // nocommit must advertise that this does NOT work if you
// index only doc values for the field ... it will say no // index only doc values for the field ... it will say no
@ -713,21 +719,20 @@ class FieldCacheImpl implements FieldCache {
protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField) protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException { throws IOException {
int maxDoc = reader.maxDoc();
final float[] values;
NumericDocValues valuesIn = reader.getNumericDocValues(key.field); NumericDocValues valuesIn = reader.getNumericDocValues(key.field);
if (valuesIn != null) { if (valuesIn != null) {
final NumericDocValues ramInstance = valuesIn.newRAMInstance();
return new Floats() {
@Override
public float get(int docID) {
return Float.intBitsToFloat((int) ramInstance.get(docID));
}
};
// nocommit should we throw exc if parser isn't // nocommit should we throw exc if parser isn't
// null? if setDocsWithField is true? // null? if setDocsWithField is true?
values = new float[maxDoc];
for(int docID=0;docID<maxDoc;docID++) {
// nocommit somewhat dangerous ... eg if user had
// indexed as DV.BYTE ...
values[docID] = Float.intBitsToFloat((int) valuesIn.get(docID));
}
} else { } else {
int maxDoc = reader.maxDoc();
final float[] values;
final FloatParser parser = (FloatParser) key.custom; final FloatParser parser = (FloatParser) key.custom;
if (parser == null) { if (parser == null) {
// Confusing: must delegate to wrapper (vs simply // Confusing: must delegate to wrapper (vs simply
@ -765,11 +770,11 @@ class FieldCacheImpl implements FieldCache {
if (setDocsWithField) { if (setDocsWithField) {
wrapper.setDocsWithField(reader, key.field, u.docsWithField); wrapper.setDocsWithField(reader, key.field, u.docsWithField);
} }
}
return new FloatsFromArray(values); return new FloatsFromArray(values);
} }
} }
}
// inherit javadocs // inherit javadocs
public Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField) throws IOException { public Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField) throws IOException {
@ -805,17 +810,20 @@ class FieldCacheImpl implements FieldCache {
protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField) protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException { throws IOException {
int maxDoc = reader.maxDoc();
final long[] values;
NumericDocValues valuesIn = reader.getNumericDocValues(key.field); NumericDocValues valuesIn = reader.getNumericDocValues(key.field);
if (valuesIn != null) { if (valuesIn != null) {
final NumericDocValues ramInstance = valuesIn.newRAMInstance();
return new Longs() {
@Override
public long get(int docID) {
return ramInstance.get(docID);
}
};
// nocommit should we throw exc if parser isn't // nocommit should we throw exc if parser isn't
// null? if setDocsWithField is true? // null? if setDocsWithField is true?
values = new long[maxDoc];
for(int docID=0;docID<maxDoc;docID++) {
values[docID] = valuesIn.get(docID);
}
} else { } else {
int maxDoc = reader.maxDoc();
final long[] values;
final LongParser parser = (LongParser) key.custom; final LongParser parser = (LongParser) key.custom;
if (parser == null) { if (parser == null) {
// Confusing: must delegate to wrapper (vs simply // Confusing: must delegate to wrapper (vs simply
@ -853,10 +861,10 @@ class FieldCacheImpl implements FieldCache {
if (setDocsWithField) { if (setDocsWithField) {
wrapper.setDocsWithField(reader, key.field, u.docsWithField); wrapper.setDocsWithField(reader, key.field, u.docsWithField);
} }
}
return new LongsFromArray(values); return new LongsFromArray(values);
} }
} }
}
// inherit javadocs // inherit javadocs
public Doubles getDoubles(AtomicReader reader, String field, boolean setDocsWithField) public Doubles getDoubles(AtomicReader reader, String field, boolean setDocsWithField)
@ -892,20 +900,21 @@ class FieldCacheImpl implements FieldCache {
@Override @Override
protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField) protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException { throws IOException {
int maxDoc = reader.maxDoc();
final double[] values;
NumericDocValues valuesIn = reader.getNumericDocValues(key.field); NumericDocValues valuesIn = reader.getNumericDocValues(key.field);
if (valuesIn != null) { if (valuesIn != null) {
final NumericDocValues ramInstance = valuesIn.newRAMInstance();
return new Doubles() {
@Override
public double get(int docID) {
return Double.longBitsToDouble(ramInstance.get(docID));
}
};
// nocommit should we throw exc if parser isn't // nocommit should we throw exc if parser isn't
// null? if setDocsWithField is true? // null? if setDocsWithField is true?
values = new double[maxDoc];
for(int docID=0;docID<maxDoc;docID++) {
// nocommit somewhat dangerous ... eg if user had
// indexed as DV.BYTE ...
values[docID] = Double.longBitsToDouble(valuesIn.get(docID));
}
} else { } else {
int maxDoc = reader.maxDoc();
final double[] values;
final DoubleParser parser = (DoubleParser) key.custom; final DoubleParser parser = (DoubleParser) key.custom;
if (parser == null) { if (parser == null) {
// Confusing: must delegate to wrapper (vs simply // Confusing: must delegate to wrapper (vs simply
@ -943,10 +952,10 @@ class FieldCacheImpl implements FieldCache {
if (setDocsWithField) { if (setDocsWithField) {
wrapper.setDocsWithField(reader, key.field, u.docsWithField); wrapper.setDocsWithField(reader, key.field, u.docsWithField);
} }
}
return new DoublesFromArray(values); return new DoublesFromArray(values);
} }
} }
}
public static class DocTermsIndexImpl extends DocTermsIndex { public static class DocTermsIndexImpl extends DocTermsIndex {
private final PagedBytes.Reader bytes; private final PagedBytes.Reader bytes;