Exemplo n.º 1
0
        /// <summary>
        /// (non-Javadoc)
        /// see com.browseengine.bobo.api.ShortFacetIterator#nextShort()
        /// </summary>
        /// <returns></returns>
        public override short NextInt16()
        {
            if (!HasNext())
            {
                throw new IndexOutOfRangeException("No more facets in this iteration");
            }

            Int16IteratorNode node = _queue.Top;

            m_facet = node.CurFacet;
            int next = TermInt16List.VALUE_MISSING;

            m_count = 0;
            while (HasNext())
            {
                node = _queue.Top;
                next = node.CurFacet;
                if ((next != -1) && (next != m_facet))
                {
                    return(m_facet);
                }
                m_count += node.CurFacetCount;
                if (node.Fetch(1))
                {
                    _queue.UpdateTop();
                }
                else
                {
                    _queue.Pop();
                }
            }
            return(TermInt16List.VALUE_MISSING);
        }
Exemplo n.º 2
0
 public Int16IteratorNode Add(Int16IteratorNode element)
 {
     m_size++;
     m_heap[m_size] = element;
     UpHeap();
     return(m_heap[1]);
 }
Exemplo n.º 3
0
        /// <summary>
        /// This version of the next() method applies the minHits from the _facet spec before returning the _facet and its hitcount
        /// </summary>
        /// <param name="minHits">the minHits from the _facet spec for CombinedFacetAccessible</param>
        /// <returns>The next _facet that obeys the minHits</returns>
        public override string Next(int minHits)
        {
            int qsize = _queue.Count;

            if (qsize == 0)
            {
                m_facet = TermInt16List.VALUE_MISSING;
                m_count = 0;
                return(null);
            }

            Int16IteratorNode node = _queue.Top;

            m_facet = node.CurFacet;
            m_count = node.CurFacetCount;
            while (true)
            {
                if (node.Fetch(minHits))
                {
                    node = _queue.UpdateTop();
                }
                else
                {
                    _queue.Pop();
                    if (--qsize > 0)
                    {
                        node = _queue.Top;
                    }
                    else
                    {
                        // we reached the end. check if this _facet obeys the minHits
                        if (m_count < minHits)
                        {
                            m_facet = TermInt16List.VALUE_MISSING;
                            m_count = 0;
                            return(null);
                        }
                        break;
                    }
                }
                short next = node.CurFacet;
                if (next != m_facet)
                {
                    // check if this _facet obeys the minHits
                    if (m_count >= minHits)
                    {
                        break;
                    }
                    // else, continue iterating to the next _facet
                    m_facet = next;
                    m_count = node.CurFacetCount;
                }
                else
                {
                    m_count += node.CurFacetCount;
                }
            }
            return(Format(m_facet));
        }
Exemplo n.º 4
0
            private void UpHeap()
            {
                int i = m_size;
                Int16IteratorNode node = m_heap[i]; // save bottom node
                int j = (int)(((uint)i) >> 1);

                while (j > 0 && (node.CurFacet < m_heap[j].CurFacet))
                {
                    m_heap[i] = m_heap[j]; // shift parents down
                    i         = j;
                    j         = (int)(((uint)j) >> 1);
                }
                m_heap[i] = node; // install saved node
            }
Exemplo n.º 5
0
 public CombinedInt16FacetIterator(List <Int16FacetIterator> iterators, int minHits)
     : this(iterators.Count)
 {
     _iterators = iterators;
     foreach (Int16FacetIterator iterator in iterators)
     {
         Int16IteratorNode node = new Int16IteratorNode(iterator);
         if (node.Fetch(minHits))
         {
             _queue.Add(node);
         }
     }
     m_facet = TermInt16List.VALUE_MISSING;
     m_count = 0;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Removes and returns the least element of the PriorityQueue in log(size)
 /// time.
 /// </summary>
 /// <returns></returns>
 public Int16IteratorNode Pop()
 {
     if (m_size > 0)
     {
         Int16IteratorNode result = m_heap[1]; // save first value
         m_heap[1]      = m_heap[m_size];      // move last to first
         m_heap[m_size] = null;                // permit GC of objects
         m_size--;
         DownHeap();                           // adjust heap
         return(result);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 7
0
 public virtual Int16IteratorNode InsertWithOverflow(Int16IteratorNode element)
 {
     if (m_size < m_maxSize)
     {
         Put(element);
         return(null);
     }
     else if (m_size > 0 && !(element.CurFacet < m_heap[1].CurFacet))
     {
         Int16IteratorNode ret = m_heap[1];
         m_heap[1] = element;
         AdjustTop();
         return(ret);
     }
     else
     {
         return(element);
     }
 }
Exemplo n.º 8
0
            private void DownHeap()
            {
                int i = 1;
                Int16IteratorNode node = m_heap[i]; // save top node
                int j = i << 1;                     // find smaller child
                int k = j + 1;

                if (k <= m_size && (m_heap[k].CurFacet < m_heap[j].CurFacet))
                {
                    j = k;
                }
                while (j <= m_size && (m_heap[j].CurFacet < node.CurFacet))
                {
                    m_heap[i] = m_heap[j]; // shift up child
                    i         = j;
                    j         = i << 1;
                    k         = j + 1;
                    if (k <= m_size && (m_heap[k].CurFacet < m_heap[j].CurFacet))
                    {
                        j = k;
                    }
                }
                m_heap[i] = node; // install saved node
            }
Exemplo n.º 9
0
 public virtual bool Insert(Int16IteratorNode element)
 {
     return(InsertWithOverflow(element) != element);
 }
Exemplo n.º 10
0
 public void Put(Int16IteratorNode element)
 {
     m_size++;
     m_heap[m_size] = element;
     UpHeap();
 }