You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2013/01/24 09:21:34 UTC

svn commit: r1437892 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/facet/ lucene/facet/src/java/org/apache/lucene/facet/search/sampling/RepeatableSampler.java

Author: shaie
Date: Thu Jan 24 08:21:34 2013
New Revision: 1437892

URL: http://svn.apache.org/viewvc?rev=1437892&view=rev
Log:
improve RepeatableSampler's inner PQ

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/RepeatableSampler.java

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/RepeatableSampler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/RepeatableSampler.java?rev=1437892&r1=1437891&r2=1437892&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/RepeatableSampler.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/RepeatableSampler.java Thu Jan 24 08:21:34 2013
@@ -279,8 +279,13 @@ public class RepeatableSampler extends S
      * into a bounded PQ (retains only sampleSize highest weights).
      */
     ScoredDocIDsIterator it = collection.iterator();
+    MI mi = null;
     while (it.next()) {
-      pq.insertWithReuse((int)(it.getDocID() * PHI_32) & 0x7FFFFFFF);
+      if (mi == null) {
+        mi = new MI();
+      }
+      mi.value = (int) (it.getDocID() * PHI_32) & 0x7FFFFFFF;
+      mi = pq.insertWithOverflow(mi);
     }
     if (returnTimings) {
       times[1] = System.currentTimeMillis();
@@ -290,18 +295,26 @@ public class RepeatableSampler extends S
      */
     Object[] heap = pq.getHeap();
     for (int si = 0; si < sampleSize; si++) {
-      sample[si] = (int)(((IntPriorityQueue.MI)(heap[si+1])).value * PHI_32I) & 0x7FFFFFFF;
+      sample[si] = (int)(((MI) heap[si+1]).value * PHI_32I) & 0x7FFFFFFF;
     }
     if (returnTimings) {
       times[2] = System.currentTimeMillis();
     }
   }
+  
+  /**
+   * A mutable integer that lets queue objects be reused once they start overflowing.
+   */
+  private static class MI {
+    MI() { }
+    public int value;
+  }
 
   /**
    * A bounded priority queue for Integers, to retain a specified number of
    * the highest-weighted values for return as a random sample.
    */
-  private static class IntPriorityQueue extends PriorityQueue<Object> {
+  private static class IntPriorityQueue extends PriorityQueue<MI> {
 
     /**
      * Creates a bounded PQ of size <code>size</code>.
@@ -312,17 +325,6 @@ public class RepeatableSampler extends S
     }
 
     /**
-     * Inserts an integer with overflow and object reuse.
-     */
-    public void insertWithReuse(int intval) {
-      if (this.mi == null) {
-        this.mi = new MI();
-      }
-      this.mi.value = intval;
-      this.mi = (MI)this.insertWithOverflow(this.mi);
-    }
-
-    /**
      * Returns the underlying data structure for faster access. Extracting elements
      * one at a time would require N logN time, and since we want the elements sorted
      * in ascending order by value (not weight), the array is useful as-is.
@@ -338,23 +340,10 @@ public class RepeatableSampler extends S
      * @return True if <code>o1</code> weighs less than <code>o2</code>.
      */
     @Override
-    public boolean lessThan(Object o1, Object o2) {
-      return ((MI)o1).value < ((MI)o2).value;
-    }
-
-    /**
-     * A mutable integer that lets queue objects be reused once they start overflowing.
-     */
-    private static class MI {
-      MI() { }
-      public int value;
+    public boolean lessThan(MI o1, MI o2) {
+      return o1.value < o2.value;
     }
 
-    /**
-     * The mutable integer instance for reuse after first overflow.
-     */
-    private MI mi;
-
   }
 
   /**