blob: 1162570b12f7dff1f7ab791e0b65886880eaee2b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.collection.mutable
/** This class implements priority queues using a heap. The
* elements of the queue have to be ordered in terms of the
* <code>Ordered[T]</code> class.
*
* @author Matthias Zenger
* @version 1.0, 03/05/2004
*/
abstract class PriorityQueueProxy[A <% Ordered[A]] extends PriorityQueue[A]
with SeqProxy[A]
{
def self: PriorityQueue[A]
/** Creates a new iterator over all elements contained in this
* object.
*
* @return the new iterator
*/
override def elements: Iterator[A] = self.elements
/** Returns the length of this priority queue.
*/
override def length: Int = self.length
/** Checks if the queue is empty.
*
* @return true, iff there is no element in the queue.
*/
override def isEmpty: Boolean = self.isEmpty
/** Inserts a single element into the priority queue.
*
* @param elem the element to insert
*/
override def +=(elem: A): Unit = self += elem
/** Adds all elements provided by an <code>Iterable</code> object
* into the priority queue.
*
* @param iter an iterable object
*/
override def ++=(iter: Iterable[A]): Unit = self ++= iter
/** Adds all elements provided by an iterator into the priority queue.
*
* @param it an iterator
*/
override def ++=(it: Iterator[A]): Unit = self ++= it
/** Adds all elements to the queue.
*
* @param elems the elements to add.
*/
override def enqueue(elems: A*): Unit = self ++= elems
/** Returns the element with the highest priority in the queue,
* and removes this element from the queue.
*
* @return the element with the highest priority.
*/
override def dequeue(): A = self.dequeue
/** Returns the element with the highest priority in the queue,
* or throws an error if there is no element contained in the queue.
*
* @return the element with the highest priority.
*/
override def max: A = self.max
/** Removes all elements from the queue. After this operation is completed,
* the queue will be empty.
*/
override def clear(): Unit = self.clear
/** Returns a regular queue containing the same elements.
*/
override def toQueue: Queue[A] = self.toQueue
/** This method clones the priority queue.
*
* @return a priority queue with the same elements.
*/
override def clone(): PriorityQueue[A] = new PriorityQueueProxy[A] {
def self = PriorityQueueProxy.this.self.clone()
}
}
|