diff options
author | Rex Kerr <ichoran@gmail.com> | 2015-08-29 13:15:26 -0700 |
---|---|---|
committer | Rex Kerr <ichoran@gmail.com> | 2015-08-29 13:15:26 -0700 |
commit | 117ea7f5aaa42d19b67fc6d5bd4ec330af43f475 (patch) | |
tree | 3c9b82379b650bc72f75dacd66eb4030e7115564 /src | |
parent | 6426d0ba5636e8aa7d16111b79c46fe22eb182b4 (diff) | |
download | scala-117ea7f5aaa42d19b67fc6d5bd4ec330af43f475.tar.gz scala-117ea7f5aaa42d19b67fc6d5bd4ec330af43f475.tar.bz2 scala-117ea7f5aaa42d19b67fc6d5bd4ec330af43f475.zip |
SI-9424 Clarify behavior of PriorityQueue toString
Clarified that PriorityQueue will not print in order and gave an example of a workaround if one needs it.
Documentation change only; no tests.
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`. |