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 Serializabletrait Cloneabletrait Growable[A]trait Clearableclass AbstractIterable[A]trait Iterable[A]class AbstractIterable[A]trait Iterable[A]trait IterableFactoryDefaults[A, Iterable]trait IterableOnce[A]class Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
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
andthis
.
Add all elements.
Add all elements.
Value parameters
- xs
-
the elements to be added
Attributes
- Definition Classes
-
Growable
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.
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
Clone this priority queue.
Clone this priority queue.
Attributes
- Returns
-
a priority queue with the same elements.
- Definition Classes
-
Cloneable -> Object
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
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
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.
Returns and removes all the elements in the priority queue.
Returns and removes all the elements in the priority queue.
Attributes
Make this priority empty.
Make this priority empty.
Attributes
- Definition Classes
-
IterableFactoryDefaults -> IterableOps
Adds all elements to the queue.
Adds all elements to the queue.
Value parameters
- elems
-
the elements to add.
Attributes
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
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
Return whether this priority is empty.
Return whether this priority is empty.
Attributes
- Definition Classes
-
IterableOnceOps
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
Return the known size of this priority queue.
Return the known size of this priority queue.
Attributes
- Definition Classes
-
Growable -> IterableOnce
Return the length of this priority queue.
Return the length of this priority queue.
Attributes
Apply/map the function f in-place
Apply/map the function f in-place
Value parameters
- f
-
the function to be applied
Attributes
Print the elements in the priority queue in order.
Print the elements in the priority queue in order.
Attributes
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
Returns the reverse of this priority queue. The new priority queue has the same elements as the original, but the opposite ordering. For example, the element with the highest priority in pq
has the lowest priority in pq.reverse
, and vice versa. Ties are handled arbitrarily. Elements with equal priority may or may not be reversed with respect to each other.
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
Attributes
- Returns
-
the reversed priority queue.
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.
Return the size of this priority queue.
Return the size of this priority queue.
Attributes
- Definition Classes
-
IterableOnceOps
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
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
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
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- Growable
Attributes
- Inherited from:
- Growable
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
IterableOps -> IterableOnceOps
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
Iterable -> Iterable -> IterableOps
- Inherited from:
- Iterable
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- Iterable
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- Builder
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- Cloneable
Attributes
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- Builder
Attributes
- Inherited from:
- Builder
Attributes
- Inherited from:
- Builder
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Definition Classes
-
IterableOps -> IterableOnceOps
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOnce
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOnceOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps
- Inherited from:
- StrictOptimizedIterableOps
Attributes
- Inherited from:
- IterableOps
Attributes
- Definition Classes
-
StrictOptimizedIterableOps -> IterableOps -> IterableOnceOps
- Inherited from:
- StrictOptimizedIterableOps
Deprecated and Inherited methods
Attributes
- Deprecated
-
[Since version 2.13.0]
Use ++ instead of ++: for collections of type Iterable - Inherited from:
- IterableOps
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
Attributes
- Deprecated
-
[Since version 2.13.0]
Use foldLeft instead of /: - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
Use foldRight instead of :\\ - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
`aggregate` is not relevant for sequential collections. Use `foldLeft(z)(seqop)` instead. - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
Use iterableFactory instead - Inherited from:
- IterableOps
Attributes
- Deprecated
-
[Since version 2.13.0]
Use `dest ++= coll` instead - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
Check .knownSize instead of .hasDefiniteSize for more actionable information (see scaladoc for details) - Inherited from:
- IterableOnceOps
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
Attributes
- Deprecated
-
[Since version 2.13.0]
Iterable.seq always returns the iterable itself - Inherited from:
- Iterable
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
Attributes
- Deprecated
-
[Since version 2.13.0]
Use .iterator instead of .toIterator - Inherited from:
- IterableOnceOps
Attributes
- Deprecated
-
[Since version 2.13.0]
Use .to(LazyList) instead of .toStream - Inherited from:
- IterableOnceOps
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
Attributes
- Deprecated
-
[Since version 2.13.0]
Use .view.slice(from, until) instead of .view(from, until) - Inherited from:
- IterableOps