PriorityQueue

scalation.PriorityQueue
See thePriorityQueue companion object
class PriorityQueue[A](implicit val ord: Ordering[A]) extends AbstractIterable[A], Iterable[A], IterableOps[A, Iterable, PriorityQueue[A]], StrictOptimizedIterableOps[A, Iterable, PriorityQueue[A]], Builder[A, PriorityQueue[A]], Cloneable[PriorityQueue[A]], Growable[A], Serializable

The PriorityQueue class implements priority queues using a heap. To prioritize elements of type A there must be an implicit Ordering [A] available at creation.

If multiple elements have the same priority in the ordering of this PriorityQueue, no guarantees are made regarding the order in which elements are returned by dequeue or dequeueAll. In particular, that means this class does not guarantee first in first out behaviour that may be incorrectly inferred from the Queue part of the name of this class.

Only the dequeue and dequeueAll methods will return elements in priority order (while removing elements from the heap). Standard collection methods 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:

Type parameters

A

type of the elements in this priority queue.

Value parameters

ord

implicit ordering used to compare the elements of type A.

Attributes

Example
val pq = collection.mutable.PriorityQueue(1, 2, 5, 3, 7)
println(pq)                  // elements probably not in order
println(pq.clone.dequeueAll) // prints ArraySeq(7, 5, 3, 2, 1)
Companion
object
Graph
Supertypes
trait Serializable
trait Cloneable[PriorityQueue[A]]
trait Cloneable
trait Builder[A, PriorityQueue[A]]
trait Growable[A]
trait Clearable
trait StrictOptimizedIterableOps[A, Iterable, PriorityQueue[A]]
class AbstractIterable[A]
trait Iterable[A]
class AbstractIterable[A]
trait Iterable[A]
trait IterableFactoryDefaults[A, Iterable]
trait IterableOps[A, Iterable, PriorityQueue[A]]
trait IterableOnceOps[A, Iterable, PriorityQueue[A]]
trait IterableOnce[A]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def ++(xs: IterableOnce[A]): PriorityQueue[A]

Adds all elements provided by a IterableOnce object into the priority queue.

Adds all elements provided by a IterableOnce object into the priority queue.

Value parameters

xs

a iterable object.

Attributes

Returns

a new priority queue containing elements of both xs and this.

override def addAll(xs: IterableOnce[A]): this.type

Add all elements.

Add all elements.

Value parameters

xs

the elements to be added

Attributes

Definition Classes
Growable
def addOne(elem: A): this.type

Insert a single element into the priority queue.

Insert a single element into the priority queue.

Value parameters

elem

the element to insert.

Attributes

Returns

this priority queue.

def clear(): Unit

Removes all elements from the queue. After this operation is completed, the queue will be empty.

Removes all elements from the queue. After this operation is completed, the queue will be empty.

Attributes

override def clone(): PriorityQueue[A]

Clone this priority queue.

Clone this priority queue.

Attributes

Returns

a priority queue with the same elements.

Definition Classes
Cloneable -> Object
override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Int

Copy the elements in this priority's heap to to an array

Copy the elements in this priority's heap to to an array

Value parameters

len

?

start

the index to start copu

xs

the array to copy the elements in this priority's heap to

Attributes

Definition Classes
IterableOnceOps
def decreaseKey(elem: A, upElem: A): Unit

Since the element's priority is being decreased, move it to a lower priority position (toward the back).

Since the element's priority is being decreased, move it to a lower priority position (toward the back).

Value parameters

elem

the element to reposition

upElem

the updated version of the element to reposition

Attributes

def dequeue(): A

Returns the element with the highest priority in the queue, and removes this element from the queue. throws NoSuchElementException

Returns the element with the highest priority in the queue, and removes this element from the queue. throws NoSuchElementException

Attributes

Returns

the element with the highest priority.

def dequeueAll[A1 >: A]: Seq[A1]

Returns and removes all the elements in the priority queue.

Returns and removes all the elements in the priority queue.

Attributes

override def empty: PriorityQueue[A]

Make this priority empty.

Make this priority empty.

Attributes

Definition Classes
IterableFactoryDefaults -> IterableOps
def enqueue(elems: A*): Unit

Adds all elements to the queue.

Adds all elements to the queue.

Value parameters

elems

the elements to add.

Attributes

override def head: 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 in the queue, or throws an error if there is no element contained in the queue.

Attributes

Returns

the element with the highest priority.

Definition Classes
IterableOps
def increaseKey(elem: A, upElem: A): Unit

Since the element's priority is being increased, move it to a higher priority position (toward the front).

Since the element's priority is being increased, move it to a higher priority position (toward the front).

Value parameters

elem

the element to reposition

upElem

the updated version of the element to reposition

Attributes

override def isEmpty: Boolean

Return whether this priority is empty.

Return whether this priority is empty.

Attributes

Definition Classes
IterableOnceOps
override def iterator: Iterator[A]

Returns an iterator which yields all the elements. Note: The order of elements returned is undefined. If you want to traverse the elements in priority queue order, use clone().dequeueAll.iterator.

Returns an iterator which yields all the elements. Note: The order of elements returned is undefined. If you want to traverse the elements in priority queue order, use clone().dequeueAll.iterator.

Attributes

Returns

an iterator over all the elements.

Definition Classes
IterableOnce
override def knownSize: Int

Return the known size of this priority queue.

Return the known size of this priority queue.

Attributes

Definition Classes
Growable -> IterableOnce
def length: Int

Return the length of this priority queue.

Return the length of this priority queue.

Attributes

def mapInPlace(f: A => A): this.type

Apply/map the function f in-place

Apply/map the function f in-place

Value parameters

f

the function to be applied

Attributes

def printInOrder: Unit

Print the elements in the priority queue in order.

Print the elements in the priority queue in order.

Attributes

def result(): PriorityQueue[A]

Return this priority queue.

Return this priority queue.

Attributes

Copy the existing data into the new array backwards; this won't put it exactly into the correct order, but will require less fixing than copying it in the original order

def reverseIterator: Iterator[A]

Returns an iterator which yields all the elements in the reverse order than that returned by the method iterator. Note: The order of elements returned is undefined.

Returns an iterator which yields all the elements in the reverse order than that returned by the method iterator. Note: The order of elements returned is undefined.

Attributes

Returns

an iterator over all elements sorted in descending order.

override def size: Int

Return the size of this priority queue.

Return the size of this priority queue.

Attributes

Definition Classes
IterableOnceOps
override def toList: List[A]

Converts this priority queue to a list. Note: the order of elements is undefined.

Converts this priority queue to a list. Note: the order of elements is undefined.

Attributes

Returns

a list containing all elements of this priority queue.

Definition Classes
IterableOnceOps
def toQueue: Queue[A]

Returns a regular queue containing the same elements. Note: the order of elements is undefined.

Returns a regular queue containing the same elements. Note: the order of elements is undefined.

Attributes

override def toString(): String

Returns a textual representation of a queue as a string.

Returns a textual representation of a queue as a string.

Attributes

Returns

the string representation of this queue.

Definition Classes
Iterable -> Any

Deprecated methods

Attributes

Deprecated
true

Inherited methods

final def ++[B >: A](suffix: IterableOnce[B]): Iterable[B]

Attributes

Inherited from:
IterableOps
final def ++=(xs: IterableOnce[A]): Growable.this.type

Attributes

Inherited from:
Growable
final def +=(elem: A): Growable.this.type

Attributes

Inherited from:
Growable
final def addString(b: StringBuilder): b.type

Attributes

Inherited from:
IterableOnceOps
final def addString(b: StringBuilder, sep: String): b.type

Attributes

Inherited from:
IterableOnceOps
def addString(b: StringBuilder, start: String, sep: String, end: String): b.type

Attributes

Inherited from:
IterableOnceOps
override def collect[B](pf: PartialFunction[A, B]): Iterable[B]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps
def collectFirst[B](pf: PartialFunction[A, B]): Option[B]

Attributes

Inherited from:
IterableOnceOps
def concat[B >: A](suffix: IterableOnce[B]): Iterable[B]

Attributes

Inherited from:
IterableOps
def copyToArray[B >: A](xs: Array[B], start: Int): Int

Attributes

Inherited from:
IterableOnceOps
def copyToArray[B >: A](xs: Array[B]): Int

Attributes

Inherited from:
IterableOnceOps
def corresponds[B](that: IterableOnce[B])(p: (A, B) => Boolean): Boolean

Attributes

Inherited from:
IterableOnceOps
def count(p: A => Boolean): Int

Attributes

Inherited from:
IterableOnceOps
def drop(n: Int): PriorityQueue[A]

Attributes

Inherited from:
IterableOps
override def dropRight(n: Int): PriorityQueue[A]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps
Inherited from:
StrictOptimizedIterableOps
def dropWhile(p: A => Boolean): PriorityQueue[A]

Attributes

Inherited from:
IterableOps
def exists(p: A => Boolean): Boolean

Attributes

Inherited from:
IterableOnceOps
override def filter(pred: A => Boolean): PriorityQueue[A]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps
override def filterNot(pred: A => Boolean): PriorityQueue[A]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps
def find(p: A => Boolean): Option[A]

Attributes

Inherited from:
IterableOnceOps
override def flatMap[B](f: A => IterableOnce[B]): Iterable[B]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps
override def flatten[B](implicit toIterableOnce: A => IterableOnce[B]): Iterable[B]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps
def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1

Attributes

Inherited from:
IterableOnceOps
def foldLeft[B](z: B)(op: (B, A) => B): B

Attributes

Inherited from:
IterableOnceOps
def foldRight[B](z: B)(op: (A, B) => B): B

Attributes

Inherited from:
IterableOnceOps
def forall(p: A => Boolean): Boolean

Attributes

Inherited from:
IterableOnceOps
def foreach[U](f: A => U): Unit

Attributes

Inherited from:
IterableOnceOps
def groupBy[K](f: A => K): Map[K, PriorityQueue[A]]

Attributes

Inherited from:
IterableOps
def groupMap[K, B](key: A => K)(f: A => B): Map[K, Iterable[B]]

Attributes

Inherited from:
IterableOps
def groupMapReduce[K, B](key: A => K)(f: A => B)(reduce: (B, B) => B): Map[K, B]

Attributes

Inherited from:
IterableOps
def grouped(size: Int): Iterator[PriorityQueue[A]]

Attributes

Inherited from:
IterableOps
def headOption: Option[A]

Attributes

Inherited from:
IterableOps

Attributes

Inherited from:
IterableOps
def inits: Iterator[PriorityQueue[A]]

Attributes

Inherited from:
IterableOps
override def isTraversableAgain: Boolean

Attributes

Definition Classes
IterableOps -> IterableOnceOps
Inherited from:
IterableOps
override def iterableFactory: IterableFactory[Iterable]

Attributes

Definition Classes
Iterable -> Iterable -> IterableOps
Inherited from:
Iterable
def last: A

Attributes

Inherited from:
IterableOps
def lastOption: Option[A]

Attributes

Inherited from:
IterableOps
def lazyZip[B](that: Iterable[B]): LazyZip2[A, B, Iterable.this.type]

Attributes

Inherited from:
Iterable
override def map[B](f: A => B): Iterable[B]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps
def mapResult[NewTo](f: (PriorityQueue[A]) => NewTo): Builder[A, NewTo]

Attributes

Inherited from:
Builder
def max[B >: A](implicit ord: Ordering[B]): A

Attributes

Inherited from:
IterableOnceOps
def maxBy[B](f: A => B)(implicit ord: Ordering[B]): A

Attributes

Inherited from:
IterableOnceOps
def maxByOption[B](f: A => B)(implicit ord: Ordering[B]): Option[A]

Attributes

Inherited from:
IterableOnceOps
def maxOption[B >: A](implicit ord: Ordering[B]): Option[A]

Attributes

Inherited from:
IterableOnceOps
def min[B >: A](implicit ord: Ordering[B]): A

Attributes

Inherited from:
IterableOnceOps
def minBy[B](f: A => B)(implicit ord: Ordering[B]): A

Attributes

Inherited from:
IterableOnceOps
def minByOption[B](f: A => B)(implicit ord: Ordering[B]): Option[A]

Attributes

Inherited from:
IterableOnceOps
def minOption[B >: A](implicit ord: Ordering[B]): Option[A]

Attributes

Inherited from:
IterableOnceOps
final def mkString: String

Attributes

Inherited from:
IterableOnceOps
final def mkString(sep: String): String

Attributes

Inherited from:
IterableOnceOps
final def mkString(start: String, sep: String, end: String): String

Attributes

Inherited from:
IterableOnceOps
def nonEmpty: Boolean

Attributes

Inherited from:
IterableOnceOps
override def partition(p: A => Boolean): (PriorityQueue[A], PriorityQueue[A])

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps
Inherited from:
StrictOptimizedIterableOps
override def partitionMap[A1, A2](f: A => Either[A1, A2]): (Iterable[A1], Iterable[A2])

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps
Inherited from:
StrictOptimizedIterableOps
def product[B >: A](implicit num: Numeric[B]): B

Attributes

Inherited from:
IterableOnceOps
def reduce[B >: A](op: (B, B) => B): B

Attributes

Inherited from:
IterableOnceOps
def reduceLeft[B >: A](op: (B, A) => B): B

Attributes

Inherited from:
IterableOnceOps
def reduceLeftOption[B >: A](op: (B, A) => B): Option[B]

Attributes

Inherited from:
IterableOnceOps
def reduceOption[B >: A](op: (B, B) => B): Option[B]

Attributes

Inherited from:
IterableOnceOps
def reduceRight[B >: A](op: (A, B) => B): B

Attributes

Inherited from:
IterableOnceOps
def reduceRightOption[B >: A](op: (A, B) => B): Option[B]

Attributes

Inherited from:
IterableOnceOps
protected def reversed: Iterable[A]

Attributes

Inherited from:
IterableOnceOps

Attributes

Inherited from:
Cloneable
def scan[B >: A](z: B)(op: (B, B) => B): Iterable[B]

Attributes

Inherited from:
IterableOps
override def scanLeft[B](z: B)(op: (B, A) => B): Iterable[B]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps
def scanRight[B](z: B)(op: (A, B) => B): Iterable[B]

Attributes

Inherited from:
IterableOps
def sizeCompare(that: Iterable[_]): Int

Attributes

Inherited from:
IterableOps
def sizeCompare(otherSize: Int): Int

Attributes

Inherited from:
IterableOps
final def sizeHint(coll: IterableOnce[_], delta: Int): Unit

Attributes

Inherited from:
Builder
def sizeHint(size: Int): Unit

Attributes

Inherited from:
Builder
final def sizeHintBounded(size: Int, boundingColl: Iterable[_]): Unit

Attributes

Inherited from:
Builder
final def sizeIs: SizeCompareOps

Attributes

Inherited from:
IterableOps
def slice(from: Int, until: Int): PriorityQueue[A]

Attributes

Inherited from:
IterableOps
def sliding(size: Int, step: Int): Iterator[PriorityQueue[A]]

Attributes

Inherited from:
IterableOps
def sliding(size: Int): Iterator[PriorityQueue[A]]

Attributes

Inherited from:
IterableOps
override def span(p: A => Boolean): (PriorityQueue[A], PriorityQueue[A])

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps
override def splitAt(n: Int): (PriorityQueue[A], PriorityQueue[A])

Attributes

Definition Classes
IterableOps -> IterableOnceOps
Inherited from:
IterableOps
def stepper[S <: Stepper[_]](implicit shape: StepperShape[A, S]): S

Attributes

Inherited from:
IterableOnce
def sum[B >: A](implicit num: Numeric[B]): B

Attributes

Inherited from:
IterableOnceOps

Attributes

Inherited from:
IterableOps
def tails: Iterator[PriorityQueue[A]]

Attributes

Inherited from:
IterableOps
def take(n: Int): PriorityQueue[A]

Attributes

Inherited from:
IterableOps
override def takeRight(n: Int): PriorityQueue[A]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps
Inherited from:
StrictOptimizedIterableOps
def takeWhile(p: A => Boolean): PriorityQueue[A]

Attributes

Inherited from:
IterableOps
override def tapEach[U](f: A => U): PriorityQueue[A]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps
def to[C1](factory: Factory[A, C1]): C1

Attributes

Inherited from:
IterableOnceOps
def toArray[B >: A : ClassTag]: Array[B]

Attributes

Inherited from:
IterableOnceOps
final def toBuffer[B >: A]: Buffer[B]

Attributes

Inherited from:
IterableOnceOps
def toIndexedSeq: IndexedSeq[A]

Attributes

Inherited from:
IterableOnceOps
def toMap[K, V](implicit ev: A <:< (K, V)): Map[K, V]

Attributes

Inherited from:
IterableOnceOps
def toSeq: Seq[A]

Attributes

Inherited from:
IterableOnceOps
def toSet[B >: A]: Set[B]

Attributes

Inherited from:
IterableOnceOps
def toVector: Vector[A]

Attributes

Inherited from:
IterableOnceOps
def transpose[B](implicit asIterable: A => Iterable[B]): Iterable[Iterable[B]]

Attributes

Inherited from:
IterableOps
override def unzip[A1, A2](implicit asPair: A => (A1, A2)): (Iterable[A1], Iterable[A2])

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps
Inherited from:
StrictOptimizedIterableOps
override def unzip3[A1, A2, A3](implicit asTriple: A => (A1, A2, A3)): (Iterable[A1], Iterable[A2], Iterable[A3])

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps
Inherited from:
StrictOptimizedIterableOps
def view: View[A]

Attributes

Inherited from:
IterableOps
def withFilter(p: A => Boolean): WithFilter[A, Iterable]

Attributes

Inherited from:
IterableOps
override def zip[B](that: IterableOnce[B]): Iterable[(A, B)]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps
Inherited from:
StrictOptimizedIterableOps
def zipAll[A1 >: A, B](that: Iterable[B], thisElem: A1, thatElem: B): Iterable[(A1, B)]

Attributes

Inherited from:
IterableOps
override def zipWithIndex: Iterable[(A, Int)]

Attributes

Definition Classes
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
Inherited from:
StrictOptimizedIterableOps

Deprecated and Inherited methods

def ++:[B >: A](that: IterableOnce[B]): Iterable[B]

Attributes

Deprecated
[Since version 2.13.0] Use ++ instead of ++: for collections of type Iterable
Inherited from:
IterableOps
final def +=(elem1: A, elem2: A, elems: A*): Growable.this.type

Attributes

Deprecated
[Since version 2.13.0] Use `++=` aka `addAll` instead of varargs `+=`; infix operations with an operand of multiple args will be deprecated
Inherited from:
Growable
final def /:[B](z: B)(op: (B, A) => B): B

Attributes

Deprecated
[Since version 2.13.0] Use foldLeft instead of /:
Inherited from:
IterableOnceOps
final def :\[B](z: B)(op: (A, B) => B): B

Attributes

Deprecated
[Since version 2.13.0] Use foldRight instead of :\\
Inherited from:
IterableOnceOps
def aggregate[B](z: => B)(seqop: (B, A) => B, combop: (B, B) => B): B

Attributes

Deprecated
[Since version 2.13.0] `aggregate` is not relevant for sequential collections. Use `foldLeft(z)(seqop)` instead.
Inherited from:
IterableOnceOps
def companion: IterableFactory[Iterable]

Attributes

Deprecated
[Since version 2.13.0] Use iterableFactory instead
Inherited from:
IterableOps
final def copyToBuffer[B >: A](dest: Buffer[B]): Unit

Attributes

Deprecated
[Since version 2.13.0] Use `dest ++= coll` instead
Inherited from:
IterableOnceOps
def hasDefiniteSize: Boolean

Attributes

Deprecated
[Since version 2.13.0] Check .knownSize instead of .hasDefiniteSize for more actionable information (see scaladoc for details)
Inherited from:
IterableOnceOps
final def repr: PriorityQueue[A]

Attributes

Deprecated
[Since version 2.13.0] Use coll instead of repr in a collection implementation, use the collection value itself from the outside
Inherited from:
IterableOps
def seq: Iterable.this.type

Attributes

Deprecated
[Since version 2.13.0] Iterable.seq always returns the iterable itself
Inherited from:
Iterable
final def toIterable: Iterable.this.type

Attributes

Deprecated
[Since version 2.13.7] toIterable is internal and will be made protected; its name is similar to `toList` or `toSeq`, but it doesn\'t copy non-immutable collections
Inherited from:
Iterable
final def toIterator: Iterator[A]

Attributes

Deprecated
[Since version 2.13.0] Use .iterator instead of .toIterator
Inherited from:
IterableOnceOps
final def toStream: Stream[A]

Attributes

Deprecated
[Since version 2.13.0] Use .to(LazyList) instead of .toStream
Inherited from:
IterableOnceOps
final def toTraversable: Iterable[A]

Attributes

Deprecated
[Since version 2.13.0] toTraversable is internal and will be made protected; its name is similar to `toList` or `toSeq`, but it doesn\'t copy non-immutable collections
Inherited from:
IterableOps
def view(from: Int, until: Int): View[A]

Attributes

Deprecated
[Since version 2.13.0] Use .view.slice(from, until) instead of .view(from, until)
Inherited from:
IterableOps

Implicits

Implicits

implicit val ord: Ordering[A]