diff options
author | Seth Tisue <seth@tisue.net> | 2015-09-02 18:28:51 -0400 |
---|---|---|
committer | Seth Tisue <seth@tisue.net> | 2015-09-02 18:28:51 -0400 |
commit | 7d2c0b354e59c61316bc118a57fa8584ebb523f8 (patch) | |
tree | 276323d67c515ff1e1b9c6a6e133e50077fab5c8 /src | |
parent | 1e47a730a9fbe7d4f465bb241272169cfefa14e6 (diff) | |
parent | 117ea7f5aaa42d19b67fc6d5bd4ec330af43f475 (diff) | |
download | scala-7d2c0b354e59c61316bc118a57fa8584ebb523f8.tar.gz scala-7d2c0b354e59c61316bc118a57fa8584ebb523f8.tar.bz2 scala-7d2c0b354e59c61316bc118a57fa8584ebb523f8.zip |
Merge pull request #4715 from Ichoran/issue/9424
SI-9424 Clarify behavior of PriorityQueue toString
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/mutable/PriorityQueue.scala | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala index d3c4161e3b..2562f60355 100644 --- a/src/library/scala/collection/mutable/PriorityQueue.scala +++ b/src/library/scala/collection/mutable/PriorityQueue.scala @@ -18,8 +18,19 @@ import generic._ * * Only the `dequeue` and `dequeueAll` methods will return methods in priority * order (while removing elements from the heap). Standard collection methods - * including `drop` and `iterator` will remove or traverse the heap in whichever - * order seems most convenient. + * including `drop`, `iterator`, and `toString` will remove or traverse the heap + * in whichever order seems most convenient. + * + * Therefore, printing a `PriorityQueue` will not reveal the priority order of + * the elements, though the highest-priority element will be printed first. To + * print the elements in order, one must duplicate the `PriorityQueue` (by using + * `clone`, for instance) and then dequeue them: + * + * @example {{{ + * val pq = collection.mutable.PriorityQueue(1, 2, 5, 3, 7) + * println(pq) // elements probably not in order + * println(pq.clone.dequeueAll) // prints Vector(7, 5, 3, 2, 1) + * }}} * * @tparam A type of the elements in this priority queue. * @param ord implicit ordering used to compare the elements of type `A`. |