/** * Returns the key+value pair with the max priority (min for minHeap mode) * <ul> * <li> key+value pair is removed from the priority queue. </li> * <li> Returns null if the priority queue is empty. </li> * <li> Runtime complexity of O(1). </li> * </ul> * * @return Key+Value pair */ public IntDoublePair poll() { if (isEmpty()) { return null; } IntDoublePair poll = peek(); int lastIndex = _values.size() - 1; swapValues(0, lastIndex); _values.removeDouble(lastIndex); _keyToIndexMap.remove(_indexToKeyMap.get(lastIndex)); _indexToKeyMap.remove(lastIndex); if (!_values.isEmpty()) { siftDown(0); } return poll; }
@Override public void remove() { if (last == -1) throw new IllegalStateException(); DoubleArrayList.this.removeDouble(last); /* * If the last operation was a next(), we are removing an element *before* us, * and we must decrease pos correspondingly. */ if (last < pos) pos--; last = -1; } };
@Override public boolean rem(final double k) { int index = indexOf(k); if (index == -1) return false; removeDouble(index); assert size <= a.length; return true; } @Override