Ejemplo n.º 1
0
        private void  DownHeap()
        {
            int             i    = 1;
            HeapedScorerDoc node = heap[i]; // save top node
            int             j    = i << 1;  // find smaller child
            int             k    = j + 1;

            if ((k <= size) && (heap[k].doc < heap[j].doc))
            {
                j = k;
            }
            while ((j <= size) && (heap[j].doc < node.doc))
            {
                heap[i] = heap[j];                 // shift up child
                i       = j;
                j       = i << 1;
                k       = j + 1;
                if (k <= size && (heap[k].doc < heap[j].doc))
                {
                    j = k;
                }
            }
            heap[i] = node;             // install saved node
            topHSD  = heap[1];
        }
Ejemplo n.º 2
0
        private HeapedScorerDoc topHSD; // same as heap[1], only for speed

        #endregion Fields

        #region Constructors

        /// <summary>Create a ScorerDocQueue with a maximum size. </summary>
        public ScorerDocQueue(int maxSize)
        {
            // assert maxSize >= 0;
            size = 0;
            int heapSize = maxSize + 1;
            heap = new HeapedScorerDoc[heapSize];
            this.maxSize = maxSize;
            topHSD = heap[1]; // initially null
        }
Ejemplo n.º 3
0
        private HeapedScorerDoc topHSD;         // same as heap[1], only for speed

        /// <summary>Create a ScorerDocQueue with a maximum size. </summary>
        public ScorerDocQueue(int maxSize)
        {
            // assert maxSize >= 0;
            size = 0;
            int heapSize = maxSize + 1;

            heap         = new HeapedScorerDoc[heapSize];
            this.maxSize = maxSize;
            topHSD       = heap[1];       // initially null
        }
Ejemplo n.º 4
0
        private void  UpHeap()
        {
            int             i    = size;
            HeapedScorerDoc node = heap[i];             // save bottom node
            int             j    = SupportClass.Number.URShift(i, 1);

            while ((j > 0) && (node.doc < heap[j].doc))
            {
                heap[i] = heap[j];                 // shift parents down
                i       = j;
                j       = SupportClass.Number.URShift(j, 1);
            }
            heap[i] = node;             // install saved node
            topHSD  = heap[1];
        }
Ejemplo n.º 5
0
 /// <summary> Adds a Scorer to the ScorerDocQueue in log(size) time if either
 /// the ScorerDocQueue is not full, or not lessThan(scorer, top()).
 /// </summary>
 /// <param name="scorer">
 /// </param>
 /// <returns> true if scorer is added, false otherwise.
 /// </returns>
 public virtual bool Insert(Scorer scorer)
 {
     if (size < maxSize)
     {
         Put(scorer);
         return(true);
     }
     else
     {
         int docNr = scorer.DocID();
         if ((size > 0) && (!(docNr < topHSD.doc)))
         {
             // heap[1] is top()
             heap[1] = new HeapedScorerDoc(this, scorer, docNr);
             DownHeap();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary> Adds a Scorer to a ScorerDocQueue in log(size) time.
 /// If one tries to add more Scorers than maxSize
 /// a RuntimeException (ArrayIndexOutOfBound) is thrown.
 /// </summary>
 public void  Put(Scorer scorer)
 {
     size++;
     heap[size] = new HeapedScorerDoc(this, scorer);
     UpHeap();
 }
Ejemplo n.º 7
0
 /// <summary> Adds a Scorer to the ScorerDocQueue in log(size) time if either
 /// the ScorerDocQueue is not full, or not lessThan(scorer, top()).
 /// </summary>
 /// <param name="scorer">
 /// </param>
 /// <returns> true if scorer is added, false otherwise.
 /// </returns>
 public virtual bool Insert(Scorer scorer)
 {
     if (size < maxSize)
     {
         Put(scorer);
         return true;
     }
     else
     {
         int docNr = scorer.DocID();
         if ((size > 0) && (!(docNr < topHSD.doc)))
         {
             // heap[1] is top()
             heap[1] = new HeapedScorerDoc(this, scorer, docNr);
             DownHeap();
             return true;
         }
         else
         {
             return false;
         }
     }
 }
Ejemplo n.º 8
0
 private void UpHeap()
 {
     int i = size;
     HeapedScorerDoc node = heap[i]; // save bottom node
     int j = Number.URShift(i, 1);
     while ((j > 0) && (node.doc < heap[j].doc))
     {
         heap[i] = heap[j]; // shift parents down
         i = j;
         j = Number.URShift(j, 1);
     }
     heap[i] = node; // install saved node
     topHSD = heap[1];
 }
Ejemplo n.º 9
0
 private void DownHeap()
 {
     int i = 1;
     HeapedScorerDoc node = heap[i]; // save top node
     int j = i << 1; // find smaller child
     int k = j + 1;
     if ((k <= size) && (heap[k].doc < heap[j].doc))
     {
         j = k;
     }
     while ((j <= size) && (heap[j].doc < node.doc))
     {
         heap[i] = heap[j]; // shift up child
         i = j;
         j = i << 1;
         k = j + 1;
         if (k <= size && (heap[k].doc < heap[j].doc))
         {
             j = k;
         }
     }
     heap[i] = node; // install saved node
     topHSD = heap[1];
 }
Ejemplo n.º 10
0
 /// <summary> Adds a Scorer to a ScorerDocQueue in log(size) time.
 /// If one tries to add more Scorers than maxSize
 /// a RuntimeException (ArrayIndexOutOfBound) is thrown.
 /// </summary>
 public void Put(Scorer scorer)
 {
     size++;
     heap[size] = new HeapedScorerDoc(this, scorer);
     UpHeap();
 }