private void DownHeap() { int i = 1; HeapedDisiDoc 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 topHDD = heap[1]; }
private HeapedDisiDoc topHDD; // same as heap[1], only for speed /// <summary> Create a DisiDocQueue with a maximum size. </summary> public DisiDocQueue(int maxSize) { // assert maxSize >= 0; size = 0; int heapSize = maxSize + 1; heap = new HeapedDisiDoc[heapSize]; this.maxSize = maxSize; topHDD = heap[1]; // initially null }
private HeapedDisiDoc topHDD; // same as heap[1], only for speed /// <summary> Create a DisiDocQueue with a maximum size. </summary> public DisiDocQueue(int maxSize) { // assert maxSize >= 0; size = 0; int heapSize = maxSize + 1; heap = new HeapedDisiDoc[heapSize]; this.maxSize = maxSize; topHDD = heap[1]; // initially null }
private void UpHeap() { int i = size; HeapedDisiDoc node = heap[i]; // save bottom node int j = (int)(((uint)i) >> 1); while ((j > 0) && (node.Doc < heap[j].Doc)) { heap[i] = heap[j]; // shift parents down i = j; j = (int)(((uint)j) >> 1); } heap[i] = node; // install saved node topHDD = heap[1]; }
///<summary>Adds a DocIdSetIterator to the DisiDocQueue in log(size) time if either /// * the DisiDocQueue is not full, or not lessThan(disi, top()). </summary> /// * <param name="disi"> </param> /// * <returns> true if DocIdSetIterator is added, false otherwise. </returns> public bool Insert(DocIdSetIterator disi) { if (size < maxSize) { Put(disi); return(true); } else { int docNr = disi.DocID(); if ((size > 0) && (!(docNr < topHDD.Doc))) // heap[1] is top() { heap[1] = new HeapedDisiDoc(disi, docNr); DownHeap(); return(true); } else { return(false); } } }
///<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(DocIdSetIterator disi) { size++; heap[size] = new HeapedDisiDoc(disi); UpHeap(); }
///<summary>Adds a DocIdSetIterator to the DisiDocQueue in log(size) time if either /// * the DisiDocQueue is not full, or not lessThan(disi, top()). </summary> /// * <param name="disi"> </param> /// * <returns> true if DocIdSetIterator is added, false otherwise. </returns> public bool Insert(DocIdSetIterator disi) { if (size < maxSize) { Put(disi); return true; } else { int docNr = disi.DocID(); if ((size > 0) && (!(docNr < topHDD.Doc))) // heap[1] is top() { heap[1] = new HeapedDisiDoc(disi, docNr); DownHeap(); return true; } else { return false; } } }
///<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(DocIdSetIterator disi) { size++; heap[size] = new HeapedDisiDoc(disi); UpHeap(); }
private void DownHeap() { int i = 1; HeapedDisiDoc 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 topHDD = heap[1]; }
private void UpHeap() { int i = size; HeapedDisiDoc node = heap[i]; // save bottom node int j = (int)(((uint)i) >> 1); while ((j > 0) && (node.Doc < heap[j].Doc)) { heap[i] = heap[j]; // shift parents down i = j; j = (int)(((uint)j) >> 1); } heap[i] = node; // install saved node topHDD = heap[1]; }