/** * Removes and returns the least element of the PriorityQueue in * log(size) time. * * @return The least element. */ public final T poll() { if (size > 0) { T 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; } }
/** * Removes and returns the least element of the PriorityQueue in * log(size) time. * * @return The least element. */ public final T poll() { if (size > 0) { T 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; } }
/** * Removes and returns the least element of the PriorityQueue in * log(size) time. * * @return The least element. */ public final T poll() { if (size > 0) { T 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; } }
/** * Removes and returns the least element of the PriorityQueue in * log(size) time. * * @return The least element. */ public final T poll() { if (size > 0) { T 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; } }
/** * Should be called when the Object at top changes values. Still log(n) * worst case, but it's at least twice as fast to * * <pre> * { * pq.top().change(); * pq.adjustTop(); * } * </pre> * * instead of * * <pre> * { * o = pq.pop(); * o.change(); * pq.push(o); * } * </pre> */ public final void adjustTop() { downHeap(); }
/** * Should be called when the Object at top changes values. Still log(n) * worst case, but it's at least twice as fast to * * <pre> * { * pq.top().change(); * pq.adjustTop(); * } * </pre> * * instead of * * <pre> * { * o = pq.pop(); * o.change(); * pq.push(o); * } * </pre> */ public final void adjustTop() { downHeap(); }
/** * Should be called when the Object at top changes values. Still log(n) * worst case, but it's at least twice as fast to * * <pre> * { * pq.top().change(); * pq.adjustTop(); * } * </pre> * * instead of * * <pre> * { * o = pq.pop(); * o.change(); * pq.push(o); * } * </pre> */ public final void adjustTop() { downHeap(); }
/** * Should be called when the Object at top changes values. Still log(n) * worst case, but it's at least twice as fast to * * <pre> * { * pq.top().change(); * pq.adjustTop(); * } * </pre> * * instead of * * <pre> * { * o = pq.pop(); * o.change(); * pq.push(o); * } * </pre> */ public final void adjustTop() { downHeap(); }