Skip to content

Commit d8e2ff6

Browse files
thestingerbrson
authored andcommitted
---
yaml --- r: 35574 b: refs/heads/master c: 7bd0d71 h: refs/heads/master v: v3
1 parent 02dbe4d commit d8e2ff6

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e00c3b05e110ab4b3cf6d60e29c59fad2b5921d6
2+
refs/heads/master: 7bd0d7155495486b35c67772eb96c930af2cf7d0
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024

trunk/src/libstd/priority_queue.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ pub struct PriorityQueue <T: Copy Ord>{
88

99
impl <T: Copy Ord> PriorityQueue<T> {
1010
/// Returns the greatest item in the queue - fails if empty
11-
pure fn top(&self) -> T { self.data[0] }
11+
pure fn top(&self) -> &self/T { &self.data[0] }
1212

1313
/// Returns the greatest item in the queue - None if empty
14-
pure fn maybe_top(&self) -> Option<T> {
14+
pure fn maybe_top(&self) -> Option<&self/T> {
1515
if self.is_empty() { None } else { Some(self.top()) }
1616
}
1717

@@ -151,7 +151,7 @@ mod tests {
151151
let mut sorted = merge_sort(data, le);
152152
let mut heap = from_vec(data);
153153
while heap.is_not_empty() {
154-
assert heap.top() == sorted.last();
154+
assert *heap.top() == sorted.last();
155155
assert heap.pop() == sorted.pop();
156156
}
157157
}
@@ -160,22 +160,22 @@ mod tests {
160160
fn test_push() {
161161
let mut heap = from_vec(~[2, 4, 9]);
162162
assert heap.len() == 3;
163-
assert heap.top() == 9;
163+
assert *heap.top() == 9;
164164
heap.push(11);
165165
assert heap.len() == 4;
166-
assert heap.top() == 11;
166+
assert *heap.top() == 11;
167167
heap.push(5);
168168
assert heap.len() == 5;
169-
assert heap.top() == 11;
169+
assert *heap.top() == 11;
170170
heap.push(27);
171171
assert heap.len() == 6;
172-
assert heap.top() == 27;
172+
assert *heap.top() == 27;
173173
heap.push(3);
174174
assert heap.len() == 7;
175-
assert heap.top() == 27;
175+
assert *heap.top() == 27;
176176
heap.push(103);
177177
assert heap.len() == 8;
178-
assert heap.top() == 103;
178+
assert *heap.top() == 103;
179179
}
180180

181181
#[test]
@@ -241,11 +241,12 @@ mod tests {
241241

242242
#[test]
243243
#[should_fail]
244-
fn test_empty_top() { from_vec::<int>(~[]).top(); }
244+
fn test_empty_top() { let empty = from_vec::<int>(~[]); empty.top(); }
245245

246246
#[test]
247247
fn test_empty_maybe_top() {
248-
assert from_vec::<int>(~[]).maybe_top().is_none();
248+
let empty = from_vec::<int>(~[]);
249+
assert empty.maybe_top().is_none();
249250
}
250251

251252
#[test]

0 commit comments

Comments
 (0)