public ShortIteratorNode Add(ShortIteratorNode element) { size++; heap[size] = element; UpHeap(); return(heap[1]); }
/// <summary> /// (non-Javadoc) /// see com.browseengine.bobo.api.ShortFacetIterator#nextShort() /// </summary> /// <returns></returns> public override short NextShort() { if (!HasNext()) { throw new IndexOutOfRangeException("No more facets in this iteration"); } ShortIteratorNode node = _queue.Top(); _facet = node.CurFacet; int next = TermShortList.VALUE_MISSING; count = 0; while (HasNext()) { node = _queue.Top(); next = node.CurFacet; if ((next != -1) && (next != _facet)) { return(_facet); } count += node.CurFacetCount; if (node.Fetch(1)) { _queue.UpdateTop(); } else { _queue.Pop(); } } return(TermShortList.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 = _queue.Size(); if (qsize == 0) { _facet = TermShortList.VALUE_MISSING; count = 0; return(null); } ShortIteratorNode node = _queue.Top(); _facet = node.CurFacet; 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 (count < minHits) { _facet = TermShortList.VALUE_MISSING; count = 0; return(null); } break; } } short next = node.CurFacet; if (next != _facet) { // check if this _facet obeys the minHits if (count >= minHits) { break; } // else, continue iterating to the next _facet _facet = next; count = node.CurFacetCount; } else { count += node.CurFacetCount; } } return(Format(_facet)); }
private void UpHeap() { int i = size; ShortIteratorNode node = heap[i]; // save bottom node int j = (int)(((uint)i) >> 1); while (j > 0 && (node.CurFacet < heap[j].CurFacet)) { heap[i] = heap[j]; // shift parents down i = j; j = (int)(((uint)j) >> 1); } heap[i] = node; // install saved node }
public CombinedShortFacetIterator(List <ShortFacetIterator> iterators, int minHits) : this(iterators.Count) { _iterators = iterators; foreach (ShortFacetIterator iterator in iterators) { ShortIteratorNode node = new ShortIteratorNode(iterator); if (node.Fetch(minHits)) { _queue.Add(node); } } _facet = TermShortList.VALUE_MISSING; count = 0; }
/// <summary> /// Removes and returns the least element of the PriorityQueue in log(size) /// time. /// </summary> /// <returns></returns> public ShortIteratorNode Pop() { if (size > 0) { ShortIteratorNode result = heap[1]; // save first value heap[1] = heap[size]; // move last to first heap[size] = null; // permit GC of objects size--; DownHeap(); // adjust heap return(result); } else { return(null); } }
public virtual ShortIteratorNode InsertWithOverflow(ShortIteratorNode element) { if (size < maxSize) { Put(element); return(null); } else if (size > 0 && !(element.CurFacet < heap[1].CurFacet)) { ShortIteratorNode ret = heap[1]; heap[1] = element; AdjustTop(); return(ret); } else { return(element); } }
private void DownHeap() { int i = 1; ShortIteratorNode node = heap[i]; // save top node int j = i << 1; // find smaller child int k = j + 1; if (k <= size && (heap[k].CurFacet < heap[j].CurFacet)) { j = k; } while (j <= size && (heap[j].CurFacet < node.CurFacet)) { heap[i] = heap[j]; // shift up child i = j; j = i << 1; k = j + 1; if (k <= size && (heap[k].CurFacet < heap[j].CurFacet)) { j = k; } } heap[i] = node; // install saved node }
public virtual bool Insert(ShortIteratorNode element) { return(InsertWithOverflow(element) != element); }
public void Put(ShortIteratorNode element) { size++; heap[size] = element; UpHeap(); }
public CombinedShortFacetIterator(List<ShortFacetIterator> iterators, int minHits) : this(iterators.Count) { _iterators = iterators; foreach (ShortFacetIterator iterator in iterators) { ShortIteratorNode node = new ShortIteratorNode(iterator); if (node.Fetch(minHits)) _queue.Add(node); } _facet = TermShortList.VALUE_MISSING; count = 0; }
public virtual ShortIteratorNode InsertWithOverflow(ShortIteratorNode element) { if (size < maxSize) { Put(element); return null; } else if (size > 0 && !(element.CurFacet < heap[1].CurFacet)) { ShortIteratorNode ret = heap[1]; heap[1] = element; AdjustTop(); return ret; } else { return element; } }
public virtual bool Insert(ShortIteratorNode element) { return InsertWithOverflow(element) != element; }
public ShortIteratorNode Add(ShortIteratorNode element) { size++; heap[size] = element; UpHeap(); return heap[1]; }