56 |
|
public class PriorityQueue<E> extends AbstractQueue<E> |
57 |
|
implements Queue<E>, java.io.Serializable { |
58 |
|
|
59 |
< |
static final long serialVersionUID = -7720805057305804111L; |
59 |
> |
private static final long serialVersionUID = -7720805057305804111L; |
60 |
|
|
61 |
|
private static final int DEFAULT_INITIAL_CAPACITY = 11; |
62 |
|
|
431 |
|
checkForComodification(); |
432 |
|
|
433 |
|
PriorityQueue.this.remove(lastRet); |
434 |
< |
if (lastRet < cursor) |
435 |
< |
cursor--; |
434 |
> |
cursor--; |
435 |
|
lastRet = 0; |
436 |
|
expectedModCount = modCount; |
437 |
|
} |
463 |
|
* Removes and returns the ith element from queue. Recall |
464 |
|
* that queue is one-based, so 1 <= i <= size. |
465 |
|
* |
467 |
– |
* XXX: Could further special-case i==size, but is it worth it? |
468 |
– |
* XXX: Could special-case i==0, but is it worth it? |
466 |
|
*/ |
467 |
|
private E remove(int i) { |
468 |
|
assert i <= size; |
517 |
|
private void fixDown(int k) { |
518 |
|
int j; |
519 |
|
if (comparator == null) { |
520 |
< |
while ((j = k << 1) <= size) { |
520 |
> |
while ((j = k << 1) <= size && j > 0) { |
521 |
|
if (j<size && ((Comparable<E>)queue[j]).compareTo((E)queue[j+1]) > 0) |
522 |
|
j++; // j indexes smallest kid |
523 |
|
if (((Comparable<E>)queue[k]).compareTo((E)queue[j]) <= 0) |
526 |
|
k = j; |
527 |
|
} |
528 |
|
} else { |
529 |
< |
while ((j = k << 1) <= size) { |
529 |
> |
while ((j = k << 1) <= size && j > 0) { |
530 |
|
if (j < size && comparator.compare((E)queue[j], (E)queue[j+1]) > 0) |
531 |
|
j++; // j indexes smallest kid |
532 |
|
if (comparator.compare((E)queue[k], (E)queue[j]) <= 0) |