Skip to content

Commit f1e8773

Browse files
thestingerbrson
authored andcommitted
add an empty PriorityQueue constructor
1 parent 02e804b commit f1e8773

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/libstd/priority_queue.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ impl <T: Ord> PriorityQueue<T> {
105105
q.to_vec()
106106
}
107107

108+
/// Create an empty PriorityQueue
109+
static pure fn new() -> PriorityQueue<T> { PriorityQueue{data: ~[],} }
110+
108111
/// Create a PriorityQueue from a vector (heapify)
109-
static pub pure fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
112+
static pure fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
110113
let mut q = PriorityQueue{data: xs,};
111114
let mut n = q.len() / 2;
112115
while n > 0 {
@@ -168,7 +171,7 @@ impl <T: Ord> PriorityQueue<T> {
168171
mod tests {
169172
use sort::merge_sort;
170173
use core::cmp::le;
171-
use priority_queue::PriorityQueue::from_vec;
174+
use priority_queue::PriorityQueue::{from_vec, new};
172175

173176
#[test]
174177
fn test_top_and_pop() {
@@ -279,30 +282,27 @@ mod tests {
279282
#[test]
280283
#[should_fail]
281284
#[ignore(cfg(windows))]
282-
fn test_empty_pop() { let mut heap = from_vec::<int>(~[]); heap.pop(); }
285+
fn test_empty_pop() { let mut heap = new::<int>(); heap.pop(); }
283286

284287
#[test]
285288
fn test_empty_maybe_pop() {
286-
let mut heap = from_vec::<int>(~[]);
289+
let mut heap = new::<int>();
287290
assert heap.maybe_pop().is_none();
288291
}
289292

290293
#[test]
291294
#[should_fail]
292295
#[ignore(cfg(windows))]
293-
fn test_empty_top() { let empty = from_vec::<int>(~[]); empty.top(); }
296+
fn test_empty_top() { let empty = new::<int>(); empty.top(); }
294297

295298
#[test]
296299
fn test_empty_maybe_top() {
297-
let empty = from_vec::<int>(~[]);
300+
let empty = new::<int>();
298301
assert empty.maybe_top().is_none();
299302
}
300303

301304
#[test]
302305
#[should_fail]
303306
#[ignore(cfg(windows))]
304-
fn test_empty_replace() {
305-
let mut heap = from_vec::<int>(~[]);
306-
heap.replace(5);
307-
}
307+
fn test_empty_replace() { let mut heap = new(); heap.replace(5); }
308308
}

0 commit comments

Comments
 (0)