diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2009-11-22 22:47:08 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2009-11-22 22:47:08 +0000 |
commit | e8e504c0f27d3d594625c9101e5f4fab9b38865e (patch) | |
tree | b851bc91ef09c3c8f10fade81b92b128989cebe8 /src/library | |
parent | 9aae43ad9f3f015811d3de8e05dfb521001c244e (diff) | |
download | scala-e8e504c0f27d3d594625c9101e5f4fab9b38865e.tar.gz scala-e8e504c0f27d3d594625c9101e5f4fab9b38865e.tar.bz2 scala-e8e504c0f27d3d594625c9101e5f4fab9b38865e.zip |
Priority queue reverse is undefined - overriden...
Priority queue reverse is undefined - overriden to throw an exception.
Reverse iterator seems to have sense - it is overriden and is defined, and some methods in SeqLike are implemented in terms of it.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/mutable/PriorityQueue.scala | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala index d6b5d12749..54505dbdf6 100644 --- a/src/library/scala/collection/mutable/PriorityQueue.scala +++ b/src/library/scala/collection/mutable/PriorityQueue.scala @@ -202,6 +202,20 @@ class PriorityQueue[A](implicit ord: Ordering[A]) } } + override def reverse = throw new UnsupportedOperationException("Priority queue cannot be reversed.") + + override def reverseIterator = new Iterator[A] { + val arr = new Array[Any](size) + iterator.copyToArray(arr) + var i = arr.size - 1 + def hasNext: Boolean = i >= 0 + def next(): A = { + val curr = arr(i) + i -= 1 + curr.asInstanceOf[A] + } + } + /** The hashCode method always yields an error, since it is not * safe to use mutable queues as keys in hash tables. * |