@@ -358,13 +358,13 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
358
358
pub fn with_capacity ( capacity : uint ) -> HashMap < K , V > {
359
359
let mut r = rand:: task_rng ( ) ;
360
360
let hasher = SipHasher :: new_with_keys ( r. gen ( ) , r. gen ( ) ) ;
361
- HashMap :: with_capacity_and_hasher ( hasher , capacity )
361
+ HashMap :: with_capacity_and_hasher ( capacity , hasher )
362
362
}
363
363
}
364
364
365
365
impl < K : Hash < S > + Eq , V , S , H : Hasher < S > > HashMap < K , V , H > {
366
366
pub fn with_hasher ( hasher : H ) -> HashMap < K , V , H > {
367
- HashMap :: with_capacity_and_hasher ( hasher , INITIAL_CAPACITY )
367
+ HashMap :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher )
368
368
}
369
369
370
370
/// Create an empty HashMap with space for at least `capacity`
@@ -374,7 +374,7 @@ impl<K: Hash<S> + Eq, V, S, H: Hasher<S>> HashMap<K, V, H> {
374
374
/// is designed to allow HashMaps to be resistant to attacks that
375
375
/// cause many collisions and very poor performance. Setting it
376
376
/// manually using this function can expose a DoS attack vector.
377
- pub fn with_capacity_and_hasher ( hasher : H , capacity : uint ) -> HashMap < K , V , H > {
377
+ pub fn with_capacity_and_hasher ( capacity : uint , hasher : H ) -> HashMap < K , V , H > {
378
378
let cap = max ( INITIAL_CAPACITY , capacity) ;
379
379
HashMap {
380
380
hasher : hasher,
@@ -587,7 +587,8 @@ impl<K: Hash<S> + Eq, V: Eq, S, H: Hasher<S>> Eq for HashMap<K, V, H> {
587
587
588
588
impl < K : Hash < S > + Eq + Clone , V : Clone , S , H : Hasher < S > + Clone > Clone for HashMap < K , V , H > {
589
589
fn clone ( & self ) -> HashMap < K , V , H > {
590
- let mut new_map = HashMap :: with_capacity_and_hasher ( self . hasher . clone ( ) , self . len ( ) ) ;
590
+ let mut new_map = HashMap :: with_capacity_and_hasher ( self . len ( ) ,
591
+ self . hasher . clone ( ) ) ;
591
592
for ( key, value) in self . iter ( ) {
592
593
new_map. insert ( ( * key) . clone ( ) , ( * value) . clone ( ) ) ;
593
594
}
@@ -714,7 +715,7 @@ impl<K> Iterator<K> for SetMoveItems<K> {
714
715
impl < K : Hash < S > + Eq , V , S , H : Hasher < S > + Default > FromIterator < ( K , V ) > for HashMap < K , V , H > {
715
716
fn from_iterator < T : Iterator < ( K , V ) > > ( iter : & mut T ) -> HashMap < K , V , H > {
716
717
let ( lower, _) = iter. size_hint ( ) ;
717
- let mut map = HashMap :: with_capacity_and_hasher ( Default :: default ( ) , lower ) ;
718
+ let mut map = HashMap :: with_capacity_and_hasher ( lower , Default :: default ( ) ) ;
718
719
map. extend ( iter) ;
719
720
map
720
721
}
@@ -730,7 +731,7 @@ impl<K: Hash<S> + Eq, V, S, H: Hasher<S> + Default> Extendable<(K, V)> for HashM
730
731
731
732
impl < K : Hash < S > + Eq , V , S , H : Hasher < S > + Default > Default for HashMap < K , V , H > {
732
733
fn default ( ) -> HashMap < K , V , H > {
733
- HashMap :: with_capacity_and_hasher ( Default :: default ( ) , INITIAL_CAPACITY )
734
+ HashMap :: with_capacity_and_hasher ( INITIAL_CAPACITY , Default :: default ( ) )
734
735
}
735
736
}
736
737
@@ -802,7 +803,7 @@ impl<T: Hash<SipState> + Eq> HashSet<T, SipHasher> {
802
803
803
804
impl < T : Hash < S > + Eq , S , H : Hasher < S > > HashSet < T , H > {
804
805
pub fn with_hasher ( hasher : H ) -> HashSet < T , H > {
805
- HashSet :: with_capacity_and_hasher ( hasher , INITIAL_CAPACITY )
806
+ HashSet :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher )
806
807
}
807
808
808
809
/// Create an empty HashSet with space for at least `capacity`
@@ -812,9 +813,9 @@ impl<T: Hash<S> + Eq, S, H: Hasher<S>> HashSet<T, H> {
812
813
/// are designed to allow HashSets to be resistant to attacks that
813
814
/// cause many collisions and very poor performance. Setting them
814
815
/// manually using this function can expose a DoS attack vector.
815
- pub fn with_capacity_and_hasher ( hasher : H , capacity : uint ) -> HashSet < T , H > {
816
+ pub fn with_capacity_and_hasher ( capacity : uint , hasher : H ) -> HashSet < T , H > {
816
817
HashSet {
817
- map : HashMap :: with_capacity_and_hasher ( hasher , capacity )
818
+ map : HashMap :: with_capacity_and_hasher ( capacity , hasher )
818
819
}
819
820
}
820
821
@@ -902,7 +903,7 @@ impl<T: fmt::Show + Hash<S> + Eq, S, H: Hasher<S>> fmt::Show for HashSet<T, H> {
902
903
impl < T : Hash < S > + Eq , S , H : Hasher < S > + Default > FromIterator < T > for HashSet < T , H > {
903
904
fn from_iterator < Iter : Iterator < T > > ( iter : & mut Iter ) -> HashSet < T , H > {
904
905
let ( lower, _) = iter. size_hint ( ) ;
905
- let mut set = HashSet :: with_capacity_and_hasher ( Default :: default ( ) , lower ) ;
906
+ let mut set = HashSet :: with_capacity_and_hasher ( lower , Default :: default ( ) ) ;
906
907
set. extend ( iter) ;
907
908
set
908
909
}
0 commit comments