Skip to content

Commit 87ef2f3

Browse files
committed
Move contructors to the top of PriorityQueue.
1 parent 9e2bb9d commit 87ef2f3

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/libcollections/priority_queue.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,25 @@ impl<T: Ord> Default for PriorityQueue<T> {
180180
}
181181

182182
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+
183202
/// An iterator visiting all values in underlying vector, in
184203
/// arbitrary order.
185204
pub fn iter<'a>(&'a self) -> Items<'a, T> {
@@ -278,25 +297,6 @@ impl<T: Ord> PriorityQueue<T> {
278297
q.into_vec()
279298
}
280299

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-
300300
// The implementations of siftup and siftdown use unsafe blocks in
301301
// order to move an element out of the vector (leaving behind a
302302
// zeroed element), shift along the others and move it back into the

0 commit comments

Comments
 (0)