You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2016/10/18 16:51:22 UTC

lucene-solr:master: LUCENE-7503: Undeprecate o.o.l.util.LongValues.

Repository: lucene-solr
Updated Branches:
  refs/heads/master 9aa764a54 -> 3be6701f1


LUCENE-7503: Undeprecate o.o.l.util.LongValues.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/3be6701f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/3be6701f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/3be6701f

Branch: refs/heads/master
Commit: 3be6701f17d9a507e07e4a3f01bcfd702bdfc806
Parents: 9aa764a
Author: Adrien Grand <jp...@gmail.com>
Authored: Tue Oct 18 18:28:39 2016 +0200
Committer: Adrien Grand <jp...@gmail.com>
Committed: Tue Oct 18 18:50:57 2016 +0200

----------------------------------------------------------------------
 .../lucene54/Lucene54DocValuesProducer.java     | 39 ++++++++++-
 .../codecs/memory/MemoryDocValuesProducer.java  | 69 +++++++-------------
 .../java/org/apache/lucene/util/LongValues.java | 21 +-----
 .../lucene/util/packed/TestDirectPacked.java    |  6 +-
 4 files changed, 67 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3be6701f/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene54/Lucene54DocValuesProducer.java
----------------------------------------------------------------------
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene54/Lucene54DocValuesProducer.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene54/Lucene54DocValuesProducer.java
index 8a44c31..1f785fe 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene54/Lucene54DocValuesProducer.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene54/Lucene54DocValuesProducer.java
@@ -491,7 +491,44 @@ final class Lucene54DocValuesProducer extends DocValuesProducer implements Close
         docsWithField = getLiveBits(entry.missingOffset, maxDoc);
       }
     }
-    return new LegacyNumericDocValuesWrapper(docsWithField, getNumeric(entry));
+    final LongValues values = getNumeric(entry);
+    return new NumericDocValues() {
+
+      int doc = -1;
+      long value;
+
+      @Override
+      public long longValue() throws IOException {
+        return value;
+      }
+
+      @Override
+      public int docID() {
+        return doc;
+      }
+
+      @Override
+      public int nextDoc() throws IOException {
+        return advance(doc + 1);
+      }
+
+      @Override
+      public int advance(int target) throws IOException {
+        for (int doc = target; doc < maxDoc; ++doc) {
+          value = values.get(doc);
+          if (value != 0 || docsWithField.get(doc)) {
+            return this.doc = doc;
+          }
+        }
+        return doc = NO_MORE_DOCS;
+      }
+
+      @Override
+      public long cost() {
+        return maxDoc;
+      }
+
+    };
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3be6701f/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesProducer.java
----------------------------------------------------------------------
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesProducer.java b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesProducer.java
index bff8c2d..b81e56e 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesProducer.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryDocValuesProducer.java
@@ -42,7 +42,6 @@ import org.apache.lucene.util.FixedBitSet;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.IntsRef;
 import org.apache.lucene.util.IntsRefBuilder;
-import org.apache.lucene.util.LongValues;
 import org.apache.lucene.util.PagedBytes;
 import org.apache.lucene.util.RamUsageEstimator;
 import org.apache.lucene.util.fst.BytesRefFSTEnum.InputOutput;
@@ -371,7 +370,12 @@ class MemoryDocValuesProducer extends DocValuesProducer {
           ramBytesUsed.addAndGet(reader.ramBytesUsed());
           numericInfo.put(field.name, Accountables.namedAccountable("block compressed", reader));
         }
-        return reader;
+        return new LegacyNumericDocValues() {
+          @Override
+          public long get(int docID) {
+            return reader.get(docID);
+          }
+        };
       case GCD_COMPRESSED:
         final long min = data.readLong();
         final long mult = data.readLong();
@@ -568,51 +572,26 @@ class MemoryDocValuesProducer extends DocValuesProducer {
         }
         addr = res;
       }
-      if (values instanceof LongValues) {
-        // probably not the greatest codec choice for this situation, but we support it
-        final LongValues longValues = (LongValues) values;
-        return new LegacySortedNumericDocValuesWrapper(new LegacySortedNumericDocValues() {
-          long startOffset;
-          long endOffset;
-          
-          @Override
-          public void setDocument(int doc) {
-            startOffset = (int) addr.get(doc);
-            endOffset = (int) addr.get(doc+1L);
-          }
-
-          @Override
-          public long valueAt(int index) {
-            return longValues.get(startOffset + index);
-          }
-
-          @Override
-          public int count() {
-            return (int) (endOffset - startOffset);
-          }
-          }, maxDoc);
-      } else {
-        return new LegacySortedNumericDocValuesWrapper(new LegacySortedNumericDocValues() {
-          int startOffset;
-          int endOffset;
-        
-          @Override
-          public void setDocument(int doc) {
-            startOffset = (int) addr.get(doc);
-            endOffset = (int) addr.get(doc+1);
-          }
+      return new LegacySortedNumericDocValuesWrapper(new LegacySortedNumericDocValues() {
+        int startOffset;
+        int endOffset;
+      
+        @Override
+        public void setDocument(int doc) {
+          startOffset = (int) addr.get(doc);
+          endOffset = (int) addr.get(doc+1);
+        }
 
-          @Override
-          public long valueAt(int index) {
-            return values.get(startOffset + index);
-          }
+        @Override
+        public long valueAt(int index) {
+          return values.get(startOffset + index);
+        }
 
-          @Override
-          public int count() {
-            return (endOffset - startOffset);
-          }
-          }, maxDoc);
-      }
+        @Override
+        public int count() {
+          return (endOffset - startOffset);
+        }
+        }, maxDoc);
     }
   }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3be6701f/lucene/core/src/java/org/apache/lucene/util/LongValues.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/LongValues.java b/lucene/core/src/java/org/apache/lucene/util/LongValues.java
index aa3b7fa..23f4d32 100644
--- a/lucene/core/src/java/org/apache/lucene/util/LongValues.java
+++ b/lucene/core/src/java/org/apache/lucene/util/LongValues.java
@@ -16,21 +16,9 @@
  */
 package org.apache.lucene.util;
 
-
-import org.apache.lucene.index.LegacyNumericDocValues;
-import org.apache.lucene.index.NumericDocValues;
-import org.apache.lucene.util.packed.PackedInts;
-
 /** Abstraction over an array of longs.
- *  This class extends NumericDocValues so that we don't need to add another
- *  level of abstraction every time we want eg. to use the {@link PackedInts}
- *  utility classes to represent a {@link LegacyNumericDocValues} instance.
- *  @lucene.internal
- *
- *  @deprecated Switch to {@link NumericDocValues} instead. */
- @Deprecated
-// TODO: cutover to iterator once codecs have all cutover?
-public abstract class LongValues extends LegacyNumericDocValues {
+ *  @lucene.internal */
+public abstract class LongValues  {
 
   /** An instance that returns the provided value. */
   public static final LongValues IDENTITY = new LongValues() {
@@ -45,9 +33,4 @@ public abstract class LongValues extends LegacyNumericDocValues {
   /** Get value at <code>index</code>. */
   public abstract long get(long index);
 
-  @Override
-  public long get(int idx) {
-    return get((long) idx);
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3be6701f/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java b/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java
index 4287125..3c5d5d8 100644
--- a/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java
+++ b/lucene/core/src/test/org/apache/lucene/util/packed/TestDirectPacked.java
@@ -19,12 +19,12 @@ package org.apache.lucene.util.packed;
 
 import java.util.Random;
 
-import org.apache.lucene.index.LegacyNumericDocValues;
 import org.apache.lucene.store.ByteArrayDataInput;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.LongValues;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
 import org.apache.lucene.util.packed.DirectReader;
@@ -46,7 +46,7 @@ public class TestDirectPacked extends LuceneTestCase {
     writer.finish();
     output.close();
     IndexInput input = dir.openInput("foo", IOContext.DEFAULT);
-    LegacyNumericDocValues reader = DirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsPerValue, 0);
+    LongValues reader = DirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsPerValue, 0);
     assertEquals(1, reader.get(0));
     assertEquals(0, reader.get(1));
     assertEquals(2, reader.get(2));
@@ -110,7 +110,7 @@ public class TestDirectPacked extends LuceneTestCase {
       writer.finish();
       output.close();
       IndexInput input = directory.openInput(name, IOContext.DEFAULT);
-      LegacyNumericDocValues reader = DirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsRequired, offset);
+      LongValues reader = DirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsRequired, offset);
       for (int j = 0; j < original.length; j++) {
         assertEquals("bpv=" + bpv, original[j], reader.get(j));
       }