7171//! let mut pq = PriorityQueue::new();
7272//!
7373//! // We're at `start`, with a zero cost
74- //! * dist.get_mut( start) = 0u;
74+ //! dist[ start] = 0u;
7575//! pq.push(State { cost: 0u, position: start });
7676//!
7777//! // Examine the frontier with lower cost nodes first (min-heap)
9696//! if next.cost < dist[next.position] {
9797//! pq.push(next);
9898//! // Relaxation, we have now found a better way
99- //! * dist.get_mut( next.position) = next.cost;
99+ //! dist[ next.position] = next.cost;
100100//! }
101101//! }
102102//! }
@@ -330,7 +330,7 @@ impl<T: Ord> PriorityQueue<T> {
330330 None => { None }
331331 Some ( mut item) => {
332332 if !self . is_empty ( ) {
333- swap ( & mut item, self . data . get_mut ( 0 ) ) ;
333+ swap ( & mut item, & mut self . data [ 0 ] ) ;
334334 self . siftdown ( 0 ) ;
335335 }
336336 Some ( item)
@@ -378,7 +378,7 @@ impl<T: Ord> PriorityQueue<T> {
378378 /// ```
379379 pub fn push_pop ( & mut self , mut item : T ) -> T {
380380 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 ] ) ;
382382 self . siftdown ( 0 ) ;
383383 }
384384 item
@@ -402,7 +402,7 @@ impl<T: Ord> PriorityQueue<T> {
402402 /// ```
403403 pub fn replace ( & mut self , mut item : T ) -> Option < T > {
404404 if !self . is_empty ( ) {
405- swap ( & mut item, self . data . get_mut ( 0 ) ) ;
405+ swap ( & mut item, & mut self . data [ 0 ] ) ;
406406 self . siftdown ( 0 ) ;
407407 Some ( item)
408408 } else {
@@ -462,40 +462,40 @@ impl<T: Ord> PriorityQueue<T> {
462462 // compared to using swaps, which involves twice as many moves.
463463 fn siftup ( & mut self , start : uint , mut pos : uint ) {
464464 unsafe {
465- let new = replace ( self . data . get_mut ( pos) , zeroed ( ) ) ;
465+ let new = replace ( & mut self . data [ pos] , zeroed ( ) ) ;
466466
467467 while pos > start {
468468 let parent = ( pos - 1 ) >> 1 ;
469469 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) ;
472472 pos = parent;
473473 continue
474474 }
475475 break
476476 }
477- ptr:: write ( self . data . get_mut ( pos) , new) ;
477+ ptr:: write ( & mut self . data [ pos] , new) ;
478478 }
479479 }
480480
481481 fn siftdown_range ( & mut self , mut pos : uint , end : uint ) {
482482 unsafe {
483483 let start = pos;
484- let new = replace ( self . data . get_mut ( pos) , zeroed ( ) ) ;
484+ let new = replace ( & mut self . data [ pos] , zeroed ( ) ) ;
485485
486486 let mut child = 2 * pos + 1 ;
487487 while child < end {
488488 let right = child + 1 ;
489489 if right < end && !( self . data [ child] > self . data [ right] ) {
490490 child = right;
491491 }
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) ;
494494 pos = child;
495495 child = 2 * pos + 1 ;
496496 }
497497
498- ptr:: write ( self . data . get_mut ( pos) , new) ;
498+ ptr:: write ( & mut self . data [ pos] , new) ;
499499 self . siftup ( start, pos) ;
500500 }
501501 }
0 commit comments