scala.collection.mutable

class PriorityQueue

[source: scala/collection/mutable/PriorityQueue.scala]

@serializable

@cloneable

class PriorityQueue[A](implicit ord : Ordering[A])
extends Seq[A] with SeqLike[A, PriorityQueue[A]] with Addable[A, PriorityQueue[A]] with Cloneable[PriorityQueue[A]] with Builder[A, PriorityQueue[A]]
This class implements priority queues using a heap. To prioritize elements of type T there must be an implicit Ordering[T] available at creation.
Author
Matthias Zenger
Version
1.0, 03/05/2004
Since
1
Direct Known Subclasses:
PriorityQueueProxy, SynchronizedPriorityQueue

Method Summary
override def + (elem1 : A, elem2 : A, elems : A*) : PriorityQueue[A]
Add two or more elements to this set.
def + (elem : A) : PriorityQueue[A]
Creates a new collection with an additional element, unless the element is already present.
override def ++ (elems : Traversable[A]) : PriorityQueue[A]
Adds all elements provided by an Iterable object into the priority queue.
override def ++ (iter : Iterator[A]) : PriorityQueue[A]
Adds all elements provided by an iterator into the priority queue.
def += (elem : A) : PriorityQueue[A]
Inserts a single element into the priority queue.
def apply (idx : Int) : A
Returns the elements at position `idx`
def clear : Unit
Removes all elements from the queue. After this operation is completed, the queue will be empty.
override def clone : PriorityQueue[A]
This method clones the priority queue.
def dequeue : A
Returns the element with the highest priority in the queue, and removes this element from the queue.
def enqueue (elems : A*) : Unit
Adds all elements to the queue.
protected def fixDown (as : Array[AnyRef], m : Int, n : Int) : Unit
protected def fixUp (as : Array[AnyRef], m : Int) : Unit
override def foreach [U](f : (A) => U) : Unit
Apply a function f to all elements of this iterable object.
override def hashCode : Int
The hashCode method always yields an error, since it is not safe to use mutable queues as keys in hash tables.
override def isEmpty : Boolean
Does this iterable contain no elements?
override def iterator : Iterator[A]
Returns an iterator which yields all the elements of the priority queue in descending priority order.
override def length : Int
Returns the length of the sequence.
def max : A
Returns the element with the highest priority in the queue, or throws an error if there is no element contained in the queue.
protected[this] override def newBuilder : PriorityQueue[A]
The builder that builds instances of CC[A]
override def repr : PriorityQueue[A]
def result : PriorityQueue[A]
Returns collection resulting from this builder. The buffer's contents are undefined afterwards.
override def reverse : PriorityQueue[A]
Returns the reverse of this queue. The priority queue that gets returned will have an inversed ordering - if for some elements x and y the original queue's ordering had compare returning an integer w, the new one will return -w, assuming the original ordering abides its contract. Note that the order of the elements will be reversed unless the compare method returns 0. In this case, such elements will be subsequent, but their corresponding subinterval may be inappropriately reversed. However, due to the compare-equals contract, they will also be equal.
override def reverseIterator : Iterator[A]
The elements of this sequence in reversed order
override def size : Int
Should always be length
override def toList : List[A]
Returns a list with all elements of this traversable object.
def toQueue : Queue[A]
Returns a regular queue containing the same elements.
override def toString : java.lang.String
Returns a textual representation of a queue as a string.
def update (idx : Int, elem : A) : Unit
Methods inherited from Builder
sizeHint, mapResult
Methods inherited from Growable
+=, ++=, ++=
Methods inherited from Seq
companion
Methods inherited from SeqLike
thisCollection, toCollection, lengthCompare, isDefinedAt, segmentLength, prefixLength, indexWhere, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, lastIndexWhere, reverseMap, reversedElements, startsWith, startsWith, endsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, updated, +:, :+, padTo, sortWith, sortWith, sortBy, toSeq, indices, view, view, equals, findLastIndexOf, equalsWith, containsSlice, projection
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from IterableLike
elements, forall, exists, find, foldRight, reduceRight, toIterable, head, take, slice, takeWhile, takeRight, dropRight, copyToArray, zip, zipAll, zipWithIndex, sameElements, toStream, canEqual, first, firstOption
Methods inherited from GenericTraversableTemplate
genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableLike
nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, count, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, tail, last, lastOption, init, drop, dropWhile, span, splitAt, copyToBuffer, copyToArray, toArray, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix, withFilter
Methods inherited from AnyRef
getClass, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
protected[this] override def newBuilder : PriorityQueue[A]
The builder that builds instances of CC[A]

override def length : Int
Returns the length of the sequence.
Overrides
SeqLike.length

override def size : Int
Should always be length
Overrides
SeqLike.size

override def isEmpty : Boolean
Does this iterable contain no elements?

override def repr : PriorityQueue[A]
Overrides
Addable.repr

override def foreach[U](f : (A) => U) : Unit
Apply a function f to all elements of this iterable object.
Parameters
f - A function that is applied for its side-effect to every element. The result (of arbitrary type U) of function `f` is discarded.
Notes
This method underlies the implementation of most other bulk operations. Implementing `foreach` with `iterator` is often suboptimal. So `foreach` should be overridden in concrete collection classes if a more efficient implementation is available.

def update(idx : Int, elem : A) : Unit
Overrides
Seq.update

def apply(idx : Int) : A
Returns the elements at position `idx`
Overrides
SeqLike.apply

def result : PriorityQueue[A]
Returns collection resulting from this builder. The buffer's contents are undefined afterwards.
Overrides
Builder.result

protected def fixUp(as : Array[AnyRef], m : Int) : Unit

protected def fixDown(as : Array[AnyRef], m : Int, n : Int) : Unit

def +=(elem : A) : PriorityQueue[A]
Inserts a single element into the priority queue.
Parameters
elem - the element to insert
Overrides
Builder.+=

def +(elem : A) : PriorityQueue[A]
Creates a new collection with an additional element, unless the element is already present.
Parameters
elem - the element to be added
Returns
a fresh collection
Overrides
Addable.+

override def +(elem1 : A, elem2 : A, elems : A*) : PriorityQueue[A]
Add two or more elements to this set.
Parameters
elem1 - the first element.
kv2 - the second element.
kvs - the remaining elements.
Overrides
Addable.+

override def ++(elems : Traversable[A]) : PriorityQueue[A]
Adds all elements provided by an Iterable object into the priority queue.
Parameters
iter - an iterable object
Overrides
Addable.++

override def ++(iter : Iterator[A]) : PriorityQueue[A]
Adds all elements provided by an iterator into the priority queue.
Parameters
it - an iterator
Overrides
Addable.++

def enqueue(elems : A*) : Unit
Adds all elements to the queue.
Parameters
elems - the elements to add.

def dequeue : A
Returns the element with the highest priority in the queue, and removes this element from the queue.
Throws
Predef.NoSuchElementException -
Returns
the element with the highest priority.

def max : A
Returns the element with the highest priority in the queue, or throws an error if there is no element contained in the queue.
Returns
the element with the highest priority.

def clear : Unit
Removes all elements from the queue. After this operation is completed, the queue will be empty.
Overrides
Builder.clear

override def iterator : Iterator[A]
Returns an iterator which yields all the elements of the priority queue in descending priority order.
Returns
an iterator over all elements sorted in descending order.

override def reverse : PriorityQueue[A]
Returns the reverse of this queue. The priority queue that gets returned will have an inversed ordering - if for some elements x and y the original queue's ordering had compare returning an integer w, the new one will return -w, assuming the original ordering abides its contract. Note that the order of the elements will be reversed unless the compare method returns 0. In this case, such elements will be subsequent, but their corresponding subinterval may be inappropriately reversed. However, due to the compare-equals contract, they will also be equal.
Overrides
SeqLike.reverse

override def reverseIterator : Iterator[A]
The elements of this sequence in reversed order
Overrides
SeqLike.reverseIterator

override def hashCode : Int
The hashCode method always yields an error, since it is not safe to use mutable queues as keys in hash tables.
Returns
never.
Overrides
SeqLike.hashCode

def toQueue : Queue[A]
Returns a regular queue containing the same elements.

override def toString : java.lang.String
Returns a textual representation of a queue as a string.
Returns
the string representation of this queue.
Overrides
SeqLike.toString

override def toList : List[A]
Returns a list with all elements of this traversable object.
Notes
Will not terminate for infinite-sized collections.

override def clone : PriorityQueue[A]
This method clones the priority queue.
Returns
a priority queue with the same elements.
Overrides
Cloneable.clone