@@ -20,7 +20,7 @@ use cmp::{max, Eq, Equiv, PartialEq};
20
20
use default:: Default ;
21
21
use fmt:: { mod, Show } ;
22
22
use hash:: { Hash , Hasher , RandomSipHasher } ;
23
- use iter:: { mod, Iterator , IteratorExt , FromIterator , Extend } ;
23
+ use iter:: { mod, Iterator , IteratorExt , FromIterator , Extend , Map } ;
24
24
use kinds:: Sized ;
25
25
use mem:: { mod, replace} ;
26
26
use num:: { Int , UnsignedInt } ;
@@ -859,7 +859,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
859
859
pub fn keys ( & self ) -> Keys < K , V > {
860
860
fn first < A , B > ( ( a, _) : ( A , B ) ) -> A { a }
861
861
862
- self . iter ( ) . map ( first)
862
+ Keys { inner : self . iter ( ) . map ( first) }
863
863
}
864
864
865
865
/// An iterator visiting all values in arbitrary order.
@@ -883,7 +883,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
883
883
pub fn values ( & self ) -> Values < K , V > {
884
884
fn second < A , B > ( ( _, b) : ( A , B ) ) -> B { b }
885
885
886
- self . iter ( ) . map ( second)
886
+ Values { inner : self . iter ( ) . map ( second) }
887
887
}
888
888
889
889
/// An iterator visiting all key-value pairs in arbitrary order.
@@ -1335,6 +1335,16 @@ pub struct MoveEntries<K, V> {
1335
1335
>
1336
1336
}
1337
1337
1338
+ /// HashMap keys iterator
1339
+ pub struct Keys < ' a , K : ' a , V : ' a > {
1340
+ inner : Map < ( & ' a K , & ' a V ) , & ' a K , Entries < ' a , K , V > , fn ( ( & ' a K , & ' a V ) ) -> & ' a K >
1341
+ }
1342
+
1343
+ /// HashMap values iterator
1344
+ pub struct Values < ' a , K : ' a , V : ' a > {
1345
+ inner : Map < ( & ' a K , & ' a V ) , & ' a V , Entries < ' a , K , V > , fn ( ( & ' a K , & ' a V ) ) -> & ' a V >
1346
+ }
1347
+
1338
1348
/// A view into a single occupied location in a HashMap
1339
1349
pub struct OccupiedEntry < ' a , K : ' a , V : ' a > {
1340
1350
elem : FullBucket < K , V , & ' a mut RawTable < K , V > > ,
@@ -1365,36 +1375,28 @@ enum VacantEntryState<K, V, M> {
1365
1375
}
1366
1376
1367
1377
impl < ' a , K , V > Iterator < ( & ' a K , & ' a V ) > for Entries < ' a , K , V > {
1368
- #[ inline]
1369
- fn next ( & mut self ) -> Option < ( & ' a K , & ' a V ) > {
1370
- self . inner . next ( )
1371
- }
1372
- #[ inline]
1373
- fn size_hint ( & self ) -> ( uint , Option < uint > ) {
1374
- self . inner . size_hint ( )
1375
- }
1378
+ #[ inline] fn next ( & mut self ) -> Option < ( & ' a K , & ' a V ) > { self . inner . next ( ) }
1379
+ #[ inline] fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
1376
1380
}
1377
1381
1378
1382
impl < ' a , K , V > Iterator < ( & ' a K , & ' a mut V ) > for MutEntries < ' a , K , V > {
1379
- #[ inline]
1380
- fn next ( & mut self ) -> Option < ( & ' a K , & ' a mut V ) > {
1381
- self . inner . next ( )
1382
- }
1383
- #[ inline]
1384
- fn size_hint ( & self ) -> ( uint , Option < uint > ) {
1385
- self . inner . size_hint ( )
1386
- }
1383
+ #[ inline] fn next ( & mut self ) -> Option < ( & ' a K , & ' a mut V ) > { self . inner . next ( ) }
1384
+ #[ inline] fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
1387
1385
}
1388
1386
1389
1387
impl < K , V > Iterator < ( K , V ) > for MoveEntries < K , V > {
1390
- #[ inline]
1391
- fn next ( & mut self ) -> Option < ( K , V ) > {
1392
- self . inner . next ( )
1393
- }
1394
- #[ inline]
1395
- fn size_hint ( & self ) -> ( uint , Option < uint > ) {
1396
- self . inner . size_hint ( )
1397
- }
1388
+ #[ inline] fn next ( & mut self ) -> Option < ( K , V ) > { self . inner . next ( ) }
1389
+ #[ inline] fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
1390
+ }
1391
+
1392
+ impl < ' a , K , V > Iterator < & ' a K > for Keys < ' a , K , V > {
1393
+ #[ inline] fn next ( & mut self ) -> Option < ( & ' a K ) > { self . inner . next ( ) }
1394
+ #[ inline] fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
1395
+ }
1396
+
1397
+ impl < ' a , K , V > Iterator < & ' a V > for Values < ' a , K , V > {
1398
+ #[ inline] fn next ( & mut self ) -> Option < ( & ' a V ) > { self . inner . next ( ) }
1399
+ #[ inline] fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
1398
1400
}
1399
1401
1400
1402
impl < ' a , K , V > OccupiedEntry < ' a , K , V > {
@@ -1448,14 +1450,6 @@ impl<'a, K, V> VacantEntry<'a, K, V> {
1448
1450
}
1449
1451
}
1450
1452
1451
- /// HashMap keys iterator
1452
- pub type Keys < ' a , K , V > =
1453
- iter:: Map < ( & ' a K , & ' a V ) , & ' a K , Entries < ' a , K , V > , fn ( ( & ' a K , & ' a V ) ) -> & ' a K > ;
1454
-
1455
- /// HashMap values iterator
1456
- pub type Values < ' a , K , V > =
1457
- iter:: Map < ( & ' a K , & ' a V ) , & ' a V , Entries < ' a , K , V > , fn ( ( & ' a K , & ' a V ) ) -> & ' a V > ;
1458
-
1459
1453
impl < K : Eq + Hash < S > , V , S , H : Hasher < S > + Default > FromIterator < ( K , V ) > for HashMap < K , V , H > {
1460
1454
fn from_iter < T : Iterator < ( K , V ) > > ( iter : T ) -> HashMap < K , V , H > {
1461
1455
let ( lower, _) = iter. size_hint ( ) ;
0 commit comments