@@ -8,10 +8,10 @@ pub struct PriorityQueue <T: Copy Ord>{
8
8
9
9
impl < T : Copy Ord > PriorityQueue < T > {
10
10
/// 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 ] }
12
12
13
13
/// 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 > {
15
15
if self . is_empty ( ) { None } else { Some ( self . top ( ) ) }
16
16
}
17
17
@@ -151,7 +151,7 @@ mod tests {
151
151
let mut sorted = merge_sort ( data, le) ;
152
152
let mut heap = from_vec ( data) ;
153
153
while heap. is_not_empty ( ) {
154
- assert heap. top ( ) == sorted. last ( ) ;
154
+ assert * heap. top ( ) == sorted. last ( ) ;
155
155
assert heap. pop ( ) == sorted. pop ( ) ;
156
156
}
157
157
}
@@ -160,22 +160,22 @@ mod tests {
160
160
fn test_push ( ) {
161
161
let mut heap = from_vec ( ~[ 2 , 4 , 9 ] ) ;
162
162
assert heap. len ( ) == 3 ;
163
- assert heap. top ( ) == 9 ;
163
+ assert * heap. top ( ) == 9 ;
164
164
heap. push ( 11 ) ;
165
165
assert heap. len ( ) == 4 ;
166
- assert heap. top ( ) == 11 ;
166
+ assert * heap. top ( ) == 11 ;
167
167
heap. push ( 5 ) ;
168
168
assert heap. len ( ) == 5 ;
169
- assert heap. top ( ) == 11 ;
169
+ assert * heap. top ( ) == 11 ;
170
170
heap. push ( 27 ) ;
171
171
assert heap. len ( ) == 6 ;
172
- assert heap. top ( ) == 27 ;
172
+ assert * heap. top ( ) == 27 ;
173
173
heap. push ( 3 ) ;
174
174
assert heap. len ( ) == 7 ;
175
- assert heap. top ( ) == 27 ;
175
+ assert * heap. top ( ) == 27 ;
176
176
heap. push ( 103 ) ;
177
177
assert heap. len ( ) == 8 ;
178
- assert heap. top ( ) == 103 ;
178
+ assert * heap. top ( ) == 103 ;
179
179
}
180
180
181
181
#[ test]
@@ -241,11 +241,12 @@ mod tests {
241
241
242
242
#[ test]
243
243
#[ should_fail]
244
- fn test_empty_top ( ) { from_vec :: < int > ( ~[ ] ) . top ( ) ; }
244
+ fn test_empty_top ( ) { let empty = from_vec :: < int > ( ~[ ] ) ; empty . top ( ) ; }
245
245
246
246
#[ test]
247
247
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 ( ) ;
249
250
}
250
251
251
252
#[ test]
0 commit comments