public Int32IteratorNode Add(Int32IteratorNode element) { m_size++; m_heap[m_size] = element; UpHeap(); return(m_heap[1]); }
/// <summary> /// (non-Javadoc) /// see com.browseengine.bobo.api.IntFacetIterator#nextInt() /// </summary> /// <returns></returns> public override int NextInt32() { if (!HasNext()) { throw new IndexOutOfRangeException("No more facets in this iteration"); } Int32IteratorNode node = m_queue.Top; m_facet = node.CurFacet; int next = TermInt32List.VALUE_MISSING; m_count = 0; while (HasNext()) { node = m_queue.Top; next = node.CurFacet; if ((next != TermInt32List.VALUE_MISSING) && (next != m_facet)) { return(m_facet); } m_count += node.CurFacetCount; if (node.Fetch(1)) { m_queue.UpdateTop(); } else { m_queue.Pop(); } } return(TermInt32List.VALUE_MISSING); }
/// <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 = m_queue.Count; if (qsize == 0) { m_facet = TermInt32List.VALUE_MISSING; m_count = 0; return(null); } Int32IteratorNode node = m_queue.Top; m_facet = node.CurFacet; m_count = node.CurFacetCount; while (true) { if (node.Fetch(minHits)) { node = m_queue.UpdateTop(); } else { m_queue.Pop(); if (--qsize > 0) { node = m_queue.Top; } else { // we reached the end. check if this facet obeys the minHits if (m_count < minHits) { m_facet = TermInt32List.VALUE_MISSING; m_count = 0; return(null); } break; } } int 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)); }
private void UpHeap() { int i = m_size; Int32IteratorNode 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 }
public CombinedInt32FacetIterator(IList <Int32FacetIterator> iterators) : this(iterators.Count) { m_iterators = iterators; foreach (Int32FacetIterator iterator in iterators) { Int32IteratorNode node = new Int32IteratorNode(iterator); if (node.Fetch(1)) { m_queue.Add(node); } } m_facet = TermInt32List.VALUE_MISSING; m_count = 0; }
/// <summary> /// Removes and returns the least element of the PriorityQueue in log(size) /// time. /// </summary> /// <returns></returns> public Int32IteratorNode Pop() { if (m_size > 0) { Int32IteratorNode 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); } }
public virtual Int32IteratorNode InsertWithOverflow(Int32IteratorNode element) { if (m_size < m_maxSize) { Put(element); return(null); } else if (m_size > 0 && !(element.CurFacet < m_heap[1].CurFacet)) { Int32IteratorNode ret = m_heap[1]; m_heap[1] = element; AdjustTop(); return(ret); } else { return(element); } }
private void DownHeap() { int i = 1; Int32IteratorNode 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 }
public virtual bool Insert(Int32IteratorNode element) { return(InsertWithOverflow(element) != element); }
public void Put(Int32IteratorNode element) { m_size++; m_heap[m_size] = element; UpHeap(); }