@@ -180,6 +180,25 @@ impl<T: Ord> Default for PriorityQueue<T> {
180
180
}
181
181
182
182
impl < T : Ord > PriorityQueue < T > {
183
+ /// Create an empty PriorityQueue
184
+ pub fn new ( ) -> PriorityQueue < T > { PriorityQueue { data : vec ! ( ) , } }
185
+
186
+ /// Create an empty PriorityQueue with capacity `capacity`
187
+ pub fn with_capacity ( capacity : uint ) -> PriorityQueue < T > {
188
+ PriorityQueue { data : Vec :: with_capacity ( capacity) }
189
+ }
190
+
191
+ /// Create a PriorityQueue from a vector (heapify)
192
+ pub fn from_vec ( xs : Vec < T > ) -> PriorityQueue < T > {
193
+ let mut q = PriorityQueue { data : xs, } ;
194
+ let mut n = q. len ( ) / 2 ;
195
+ while n > 0 {
196
+ n -= 1 ;
197
+ q. siftdown ( n)
198
+ }
199
+ q
200
+ }
201
+
183
202
/// An iterator visiting all values in underlying vector, in
184
203
/// arbitrary order.
185
204
pub fn iter < ' a > ( & ' a self ) -> Items < ' a , T > {
@@ -278,25 +297,6 @@ impl<T: Ord> PriorityQueue<T> {
278
297
q. into_vec ( )
279
298
}
280
299
281
- /// Create an empty PriorityQueue
282
- pub fn new ( ) -> PriorityQueue < T > { PriorityQueue { data : vec ! ( ) , } }
283
-
284
- /// Create an empty PriorityQueue with capacity `capacity`
285
- pub fn with_capacity ( capacity : uint ) -> PriorityQueue < T > {
286
- PriorityQueue { data : Vec :: with_capacity ( capacity) }
287
- }
288
-
289
- /// Create a PriorityQueue from a vector (heapify)
290
- pub fn from_vec ( xs : Vec < T > ) -> PriorityQueue < T > {
291
- let mut q = PriorityQueue { data : xs, } ;
292
- let mut n = q. len ( ) / 2 ;
293
- while n > 0 {
294
- n -= 1 ;
295
- q. siftdown ( n)
296
- }
297
- q
298
- }
299
-
300
300
// The implementations of siftup and siftdown use unsafe blocks in
301
301
// order to move an element out of the vector (leaving behind a
302
302
// zeroed element), shift along the others and move it back into the
0 commit comments