@@ -149,15 +149,15 @@ impl<N: Hash + Eq + Clone, E: Eq + Hash + Clone, V> DependencyQueue<N, E, V> {
149
149
///
150
150
/// A package is ready to be built when it has 0 un-built dependencies. If
151
151
/// `None` is returned then no packages are ready to be built.
152
- pub fn dequeue ( & mut self ) -> Option < ( N , V ) > {
153
- let key = self
152
+ pub fn dequeue ( & mut self ) -> Option < ( N , V , usize ) > {
153
+ let ( key, priority ) = self
154
154
. dep_map
155
155
. iter ( )
156
156
. filter ( |( _, ( deps, _) ) | deps. is_empty ( ) )
157
- . map ( |( key, _) | key. clone ( ) )
158
- . max_by_key ( |k| self . priority [ k ] ) ?;
157
+ . map ( |( key, _) | ( key. clone ( ) , self . priority [ key ] ) )
158
+ . max_by_key ( |( _ , priority ) | * priority) ?;
159
159
let ( _, data) = self . dep_map . remove ( & key) . unwrap ( ) ;
160
- Some ( ( key, data) )
160
+ Some ( ( key, data, priority ) )
161
161
}
162
162
163
163
/// Returns `true` if there are remaining packages to be built.
@@ -170,13 +170,6 @@ impl<N: Hash + Eq + Clone, E: Eq + Hash + Clone, V> DependencyQueue<N, E, V> {
170
170
self . dep_map . len ( )
171
171
}
172
172
173
- /// Returns the relative priority of a node. Higher priorities should be scheduled sooner.
174
- /// Currently computed as the transitive cost of the given node: its own, plus the cost of its
175
- /// reverse dependencies.
176
- pub ( crate ) fn priority ( & self , node : & N ) -> usize {
177
- self . priority [ node]
178
- }
179
-
180
173
/// Indicate that something has finished.
181
174
///
182
175
/// Calling this function indicates that the `node` has produced `edge`. All
@@ -220,19 +213,19 @@ mod test {
220
213
q. queue ( 5 , ( ) , vec ! [ ( 4 , ( ) ) , ( 3 , ( ) ) ] , 1 ) ;
221
214
q. queue_finished ( ) ;
222
215
223
- assert_eq ! ( q. dequeue( ) , Some ( ( 1 , ( ) ) ) ) ;
224
- assert_eq ! ( q. dequeue( ) , Some ( ( 3 , ( ) ) ) ) ;
216
+ assert_eq ! ( q. dequeue( ) , Some ( ( 1 , ( ) , 5 ) ) ) ;
217
+ assert_eq ! ( q. dequeue( ) , Some ( ( 3 , ( ) , 4 ) ) ) ;
225
218
assert_eq ! ( q. dequeue( ) , None ) ;
226
219
q. finish ( & 3 , & ( ) ) ;
227
220
assert_eq ! ( q. dequeue( ) , None ) ;
228
221
q. finish ( & 1 , & ( ) ) ;
229
- assert_eq ! ( q. dequeue( ) , Some ( ( 2 , ( ) ) ) ) ;
222
+ assert_eq ! ( q. dequeue( ) , Some ( ( 2 , ( ) , 4 ) ) ) ;
230
223
assert_eq ! ( q. dequeue( ) , None ) ;
231
224
q. finish ( & 2 , & ( ) ) ;
232
- assert_eq ! ( q. dequeue( ) , Some ( ( 4 , ( ) ) ) ) ;
225
+ assert_eq ! ( q. dequeue( ) , Some ( ( 4 , ( ) , 3 ) ) ) ;
233
226
assert_eq ! ( q. dequeue( ) , None ) ;
234
227
q. finish ( & 4 , & ( ) ) ;
235
- assert_eq ! ( q. dequeue( ) , Some ( ( 5 , ( ) ) ) ) ;
228
+ assert_eq ! ( q. dequeue( ) , Some ( ( 5 , ( ) , 2 ) ) ) ;
236
229
}
237
230
238
231
#[ test]
@@ -245,16 +238,16 @@ mod test {
245
238
q. queue ( 4 , ( ) , vec ! [ ( 2 , ( ) ) , ( 3 , ( ) ) ] , 1 ) ;
246
239
q. queue_finished ( ) ;
247
240
248
- assert_eq ! ( q. dequeue( ) , Some ( ( 3 , ( ) ) ) ) ;
249
- assert_eq ! ( q. dequeue( ) , Some ( ( 1 , ( ) ) ) ) ;
241
+ assert_eq ! ( q. dequeue( ) , Some ( ( 3 , ( ) , 9 ) ) ) ;
242
+ assert_eq ! ( q. dequeue( ) , Some ( ( 1 , ( ) , 4 ) ) ) ;
250
243
assert_eq ! ( q. dequeue( ) , None ) ;
251
244
q. finish ( & 3 , & ( ) ) ;
252
245
assert_eq ! ( q. dequeue( ) , None ) ;
253
246
q. finish ( & 1 , & ( ) ) ;
254
- assert_eq ! ( q. dequeue( ) , Some ( ( 2 , ( ) ) ) ) ;
247
+ assert_eq ! ( q. dequeue( ) , Some ( ( 2 , ( ) , 3 ) ) ) ;
255
248
assert_eq ! ( q. dequeue( ) , None ) ;
256
249
q. finish ( & 2 , & ( ) ) ;
257
- assert_eq ! ( q. dequeue( ) , Some ( ( 4 , ( ) ) ) ) ;
250
+ assert_eq ! ( q. dequeue( ) , Some ( ( 4 , ( ) , 2 ) ) ) ;
258
251
assert_eq ! ( q. dequeue( ) , None ) ;
259
252
q. finish ( & 4 , & ( ) ) ;
260
253
assert_eq ! ( q. dequeue( ) , None ) ;
0 commit comments