lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject svn commit: r1418060 - /lucene/dev/branches/lucene4547/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesFormat.java
Date Thu, 06 Dec 2012 20:35:27 GMT
Author: jpountz
Date: Thu Dec  6 20:35:26 2012
New Revision: 1418060

URL: http://svn.apache.org/viewvc?rev=1418060&view=rev
Log:
Fix nocommit: use packed ints to make MemoryDocValues more memory-efficient.

Modified:
    lucene/dev/branches/lucene4547/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesFormat.java

Modified: lucene/dev/branches/lucene4547/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesFormat.java?rev=1418060&r1=1418059&r2=1418060&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesFormat.java
(original)
+++ lucene/dev/branches/lucene4547/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesFormat.java
Thu Dec  6 20:35:26 2012
@@ -31,6 +31,7 @@ import org.apache.lucene.index.SegmentRe
 import org.apache.lucene.index.SegmentWriteState;
 import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.packed.PackedInts;
 
 /** Indexes doc values to disk and loads them in RAM at
  *  search time. */
@@ -57,21 +58,22 @@ public class MemoryDocValuesFormat exten
       public NumericDocValues getNumeric(FieldInfo field) throws IOException {
         NumericDocValues valuesIn = producer.getNumeric(field);
 
-        // nocommit more ram efficient
         final int maxDoc = valuesIn.size();
         final long minValue = valuesIn.minValue();
         final long maxValue = valuesIn.maxValue();
 
-        final long[] values = new long[maxDoc];
+        final long delta = maxValue - minValue;
+        final int bitsRequired = delta < 0 ? 64 : PackedInts.bitsRequired(delta);
+        final PackedInts.Mutable values = PackedInts.getMutable(maxDoc, bitsRequired, PackedInts.COMPACT);
         for(int docID=0;docID<maxDoc;docID++) {
-          values[docID] = valuesIn.get(docID);
+          values.set(docID, valuesIn.get(docID) - minValue);
         }
 
         return new NumericDocValues() {
 
           @Override
           public long get(int docID) {
-            return values[docID];
+            return minValue + values.get(docID);
           }
 
           @Override



Mime
View raw message