--- jsr166/src/main/java/util/PriorityQueue.java 2015/09/20 16:20:21 1.107 +++ jsr166/src/main/java/util/PriorityQueue.java 2016/11/29 18:11:28 1.112 @@ -54,7 +54,8 @@ import java.util.function.Consumer; *

This class and its iterator implement all of the * optional methods of the {@link Collection} and {@link * Iterator} interfaces. The Iterator provided in method {@link - * #iterator()} is not guaranteed to traverse the elements of + * #iterator()} and the Spliterator provided in method {@link #spliterator()} + * are not guaranteed to traverse the elements of * the priority queue in any particular order. If you need ordered * traversal, consider using {@code Arrays.sort(pq.toArray())}. * @@ -337,11 +338,8 @@ public class PriorityQueue extends Ab int i = size; if (i >= queue.length) grow(i + 1); + siftUp(i, e); size = i + 1; - if (i == 0) - queue[0] = e; - else - siftUp(i, e); return true; } @@ -729,6 +727,7 @@ public class PriorityQueue extends Ab /** * Establishes the heap invariant (described above) in the entire tree, * assuming nothing about the order of the elements prior to the call. + * This classic algorithm due to Floyd (1964) is known to be O(size). */ @SuppressWarnings("unchecked") private void heapify() { @@ -752,11 +751,11 @@ public class PriorityQueue extends Ab /** * Saves this queue to a stream (that is, serializes it). * + * @param s the stream + * @throws java.io.IOException if an I/O error occurs * @serialData The length of the array backing the instance is * emitted (int), followed by all of its elements * (each an {@code Object}) in the proper order. - * @param s the stream - * @throws java.io.IOException if an I/O error occurs */ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { @@ -802,7 +801,8 @@ public class PriorityQueue extends Ab /** * Creates a late-binding * and fail-fast {@link Spliterator} over the elements in this - * queue. + * queue. The spliterator does not traverse elements in any particular order + * (the {@link Spliterator#ORDERED ORDERED} characteristic is not reported). * *

The {@code Spliterator} reports {@link Spliterator#SIZED}, * {@link Spliterator#SUBSIZED}, and {@link Spliterator#NONNULL}. @@ -826,7 +826,7 @@ public class PriorityQueue extends Ab private int fence; // -1 until first use private int expectedModCount; // initialized when fence set - /** Creates new spliterator covering the given range */ + /** Creates new spliterator covering the given range. */ PriorityQueueSpliterator(PriorityQueue pq, int origin, int fence, int expectedModCount) { this.pq = pq;