File tree Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -230,7 +230,7 @@ impl<T> TrieNode<T> {
230
230
pure fn each_reverse ( & self , f : fn ( & ( uint, & self /T ) ) -> bool ) {
231
231
for uint:: range_rev( self . children. len( ) , 0 ) |idx| {
232
232
match self . children [ idx - 1 ] {
233
- Internal ( ref x) => x. each ( f) ,
233
+ Internal ( ref x) => x. each_reverse ( f) ,
234
234
External ( k, ref v) => if !f ( & ( k, v) ) { return } ,
235
235
Nothing => ( )
236
236
}
@@ -366,4 +366,40 @@ mod tests {
366
366
check_integrity( & trie. root) ;
367
367
}
368
368
}
369
+
370
+ #[ test]
371
+ fn test_each ( ) {
372
+ let mut m = TrieMap : : new( ) ;
373
+
374
+ assert m. insert( 3 , 6 ) ;
375
+ assert m. insert( 0 , 0 ) ;
376
+ assert m. insert( 4 , 8 ) ;
377
+ assert m. insert( 2 , 4 ) ;
378
+ assert m. insert( 1 , 2 ) ;
379
+
380
+ let mut n = 0 ;
381
+ for m. each |& ( k, v) | {
382
+ assert k == n;
383
+ assert * v == n * 2 ;
384
+ n += 1 ;
385
+ }
386
+ }
387
+
388
+ #[ test]
389
+ fn test_each_reverse( ) {
390
+ let mut m = TrieMap :: new( ) ;
391
+
392
+ assert m. insert( 3 , 6 ) ;
393
+ assert m. insert( 0 , 0 ) ;
394
+ assert m. insert( 4 , 8 ) ;
395
+ assert m. insert( 2 , 4 ) ;
396
+ assert m. insert( 1 , 2 ) ;
397
+
398
+ let mut n = 4 ;
399
+ for m. each_reverse |& ( k, v) | {
400
+ assert k == n;
401
+ assert * v == n * 2 ;
402
+ n -= 1 ;
403
+ }
404
+ }
369
405
}
You can’t perform that action at this time.
0 commit comments