@@ -97,41 +97,39 @@ impl <T: Copy Ord> PriorityQueue<T> {
97
97
q
98
98
}
99
99
100
- priv fn siftup ( & mut self , startpos : uint , pos : uint ) {
100
+ priv fn siftup ( & mut self , start : uint , pos : uint ) {
101
101
let mut pos = pos;
102
- let newitem = self . data [ pos] ;
103
-
104
- while pos > startpos {
105
- let parentpos = ( pos - 1 ) >> 1 ;
106
- let parent = self . data [ parentpos] ;
107
- if newitem > parent {
108
- self . data [ pos] = parent;
109
- pos = parentpos;
102
+ let new = self . data [ pos] ;
103
+
104
+ while pos > start {
105
+ let parent = ( pos - 1 ) >> 1 ;
106
+ if new > self . data [ parent] {
107
+ self . data [ pos] = self . data [ parent] ;
108
+ pos = parent;
110
109
loop
111
110
}
112
111
break
113
112
}
114
- self . data [ pos] = newitem ;
113
+ self . data [ pos] = new ;
115
114
}
116
115
117
- priv fn siftdown_range ( & mut self , pos : uint , endpos : uint ) {
116
+ priv fn siftdown_range ( & mut self , pos : uint , end : uint ) {
118
117
let mut pos = pos;
119
- let startpos = pos;
120
- let newitem = self . data [ pos] ;
121
-
122
- let mut childpos = 2 * pos + 1 ;
123
- while childpos < endpos {
124
- let rightpos = childpos + 1 ;
125
- if rightpos < endpos &&
126
- !( self . data [ childpos] > self . data [ rightpos] ) {
127
- childpos = rightpos;
118
+ let start = pos;
119
+ let new = self . data [ pos] ;
120
+
121
+ let mut child = 2 * pos + 1 ;
122
+ while child < end {
123
+ let right = child + 1 ;
124
+ if right < end && !( self . data [ child] > self . data [ right] ) {
125
+ child = right;
128
126
}
129
- self . data [ pos] = self . data [ childpos ] ;
130
- pos = childpos ;
131
- childpos = 2 * pos + 1 ;
127
+ self . data [ pos] = self . data [ child ] ;
128
+ pos = child ;
129
+ child = 2 * pos + 1 ;
132
130
}
133
- self . data [ pos] = newitem ;
134
- self . siftup ( startpos , pos) ;
131
+ self . data [ pos] = new ;
132
+ self . siftup ( start , pos) ;
135
133
}
136
134
137
135
priv fn siftdown ( & mut self , pos : uint ) {
0 commit comments