71
71
//! let mut pq = PriorityQueue::new();
72
72
//!
73
73
//! // We're at `start`, with a zero cost
74
- //! * dist.get_mut( start) = 0u;
74
+ //! dist[ start] = 0u;
75
75
//! pq.push(State { cost: 0u, position: start });
76
76
//!
77
77
//! // Examine the frontier with lower cost nodes first (min-heap)
96
96
//! if next.cost < dist[next.position] {
97
97
//! pq.push(next);
98
98
//! // Relaxation, we have now found a better way
99
- //! * dist.get_mut( next.position) = next.cost;
99
+ //! dist[ next.position] = next.cost;
100
100
//! }
101
101
//! }
102
102
//! }
@@ -330,7 +330,7 @@ impl<T: Ord> PriorityQueue<T> {
330
330
None => { None }
331
331
Some ( mut item) => {
332
332
if !self . is_empty ( ) {
333
- swap ( & mut item, self . data . get_mut ( 0 ) ) ;
333
+ swap ( & mut item, & mut self . data [ 0 ] ) ;
334
334
self . siftdown ( 0 ) ;
335
335
}
336
336
Some ( item)
@@ -378,7 +378,7 @@ impl<T: Ord> PriorityQueue<T> {
378
378
/// ```
379
379
pub fn push_pop ( & mut self , mut item : T ) -> T {
380
380
if !self . is_empty ( ) && * self . top ( ) . unwrap ( ) > item {
381
- swap ( & mut item, self . data . get_mut ( 0 ) ) ;
381
+ swap ( & mut item, & mut self . data [ 0 ] ) ;
382
382
self . siftdown ( 0 ) ;
383
383
}
384
384
item
@@ -402,7 +402,7 @@ impl<T: Ord> PriorityQueue<T> {
402
402
/// ```
403
403
pub fn replace ( & mut self , mut item : T ) -> Option < T > {
404
404
if !self . is_empty ( ) {
405
- swap ( & mut item, self . data . get_mut ( 0 ) ) ;
405
+ swap ( & mut item, & mut self . data [ 0 ] ) ;
406
406
self . siftdown ( 0 ) ;
407
407
Some ( item)
408
408
} else {
@@ -462,40 +462,40 @@ impl<T: Ord> PriorityQueue<T> {
462
462
// compared to using swaps, which involves twice as many moves.
463
463
fn siftup ( & mut self , start : uint , mut pos : uint ) {
464
464
unsafe {
465
- let new = replace ( self . data . get_mut ( pos) , zeroed ( ) ) ;
465
+ let new = replace ( & mut self . data [ pos] , zeroed ( ) ) ;
466
466
467
467
while pos > start {
468
468
let parent = ( pos - 1 ) >> 1 ;
469
469
if new > self . data [ parent] {
470
- let x = replace ( self . data . get_mut ( parent) , zeroed ( ) ) ;
471
- ptr:: write ( self . data . get_mut ( pos) , x) ;
470
+ let x = replace ( & mut self . data [ parent] , zeroed ( ) ) ;
471
+ ptr:: write ( & mut self . data [ pos] , x) ;
472
472
pos = parent;
473
473
continue
474
474
}
475
475
break
476
476
}
477
- ptr:: write ( self . data . get_mut ( pos) , new) ;
477
+ ptr:: write ( & mut self . data [ pos] , new) ;
478
478
}
479
479
}
480
480
481
481
fn siftdown_range ( & mut self , mut pos : uint , end : uint ) {
482
482
unsafe {
483
483
let start = pos;
484
- let new = replace ( self . data . get_mut ( pos) , zeroed ( ) ) ;
484
+ let new = replace ( & mut self . data [ pos] , zeroed ( ) ) ;
485
485
486
486
let mut child = 2 * pos + 1 ;
487
487
while child < end {
488
488
let right = child + 1 ;
489
489
if right < end && !( self . data [ child] > self . data [ right] ) {
490
490
child = right;
491
491
}
492
- let x = replace ( self . data . get_mut ( child) , zeroed ( ) ) ;
493
- ptr:: write ( self . data . get_mut ( pos) , x) ;
492
+ let x = replace ( & mut self . data [ child] , zeroed ( ) ) ;
493
+ ptr:: write ( & mut self . data [ pos] , x) ;
494
494
pos = child;
495
495
child = 2 * pos + 1 ;
496
496
}
497
497
498
- ptr:: write ( self . data . get_mut ( pos) , new) ;
498
+ ptr:: write ( & mut self . data [ pos] , new) ;
499
499
self . siftup ( start, pos) ;
500
500
}
501
501
}
0 commit comments