diff --git a/src/libcollections/hashmap.rs b/src/libcollections/hashmap.rs index b4b843289f8..1d73fae11b0 100644 --- a/src/libcollections/hashmap.rs +++ b/src/libcollections/hashmap.rs @@ -358,13 +358,13 @@ impl HashMap { pub fn with_capacity(capacity: uint) -> HashMap { let mut r = rand::task_rng(); let hasher = SipHasher::new_with_keys(r.gen(), r.gen()); - HashMap::with_capacity_and_hasher(hasher, capacity) + HashMap::with_capacity_and_hasher(capacity, hasher) } } impl + Eq, V, S, H: Hasher> HashMap { pub fn with_hasher(hasher: H) -> HashMap { - HashMap::with_capacity_and_hasher(hasher, INITIAL_CAPACITY) + HashMap::with_capacity_and_hasher(INITIAL_CAPACITY, hasher) } /// Create an empty HashMap with space for at least `capacity` @@ -374,7 +374,7 @@ impl + Eq, V, S, H: Hasher> HashMap { /// is designed to allow HashMaps to be resistant to attacks that /// cause many collisions and very poor performance. Setting it /// manually using this function can expose a DoS attack vector. - pub fn with_capacity_and_hasher(hasher: H, capacity: uint) -> HashMap { + pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashMap { let cap = max(INITIAL_CAPACITY, capacity); HashMap { hasher: hasher, @@ -587,7 +587,8 @@ impl + Eq, V: Eq, S, H: Hasher> Eq for HashMap { impl + Eq + Clone, V:Clone, S, H: Hasher + Clone> Clone for HashMap { fn clone(&self) -> HashMap { - let mut new_map = HashMap::with_capacity_and_hasher(self.hasher.clone(), self.len()); + let mut new_map = HashMap::with_capacity_and_hasher(self.len(), + self.hasher.clone()); for (key, value) in self.iter() { new_map.insert((*key).clone(), (*value).clone()); } @@ -714,7 +715,7 @@ impl Iterator for SetMoveItems { impl + Eq, V, S, H: Hasher + Default> FromIterator<(K, V)> for HashMap { fn from_iterator>(iter: &mut T) -> HashMap { let (lower, _) = iter.size_hint(); - let mut map = HashMap::with_capacity_and_hasher(Default::default(), lower); + let mut map = HashMap::with_capacity_and_hasher(lower, Default::default()); map.extend(iter); map } @@ -730,7 +731,7 @@ impl + Eq, V, S, H: Hasher + Default> Extendable<(K, V)> for HashM impl + Eq, V, S, H: Hasher + Default> Default for HashMap { fn default() -> HashMap { - HashMap::with_capacity_and_hasher(Default::default(), INITIAL_CAPACITY) + HashMap::with_capacity_and_hasher(INITIAL_CAPACITY, Default::default()) } } @@ -802,7 +803,7 @@ impl + Eq> HashSet { impl + Eq, S, H: Hasher> HashSet { pub fn with_hasher(hasher: H) -> HashSet { - HashSet::with_capacity_and_hasher(hasher, INITIAL_CAPACITY) + HashSet::with_capacity_and_hasher(INITIAL_CAPACITY, hasher) } /// Create an empty HashSet with space for at least `capacity` @@ -812,9 +813,9 @@ impl + Eq, S, H: Hasher> HashSet { /// are designed to allow HashSets to be resistant to attacks that /// cause many collisions and very poor performance. Setting them /// manually using this function can expose a DoS attack vector. - pub fn with_capacity_and_hasher(hasher: H, capacity: uint) -> HashSet { + pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashSet { HashSet { - map: HashMap::with_capacity_and_hasher(hasher, capacity) + map: HashMap::with_capacity_and_hasher(capacity, hasher) } } @@ -902,7 +903,7 @@ impl + Eq, S, H: Hasher> fmt::Show for HashSet { impl + Eq, S, H: Hasher + Default> FromIterator for HashSet { fn from_iterator>(iter: &mut Iter) -> HashSet { let (lower, _) = iter.size_hint(); - let mut set = HashSet::with_capacity_and_hasher(Default::default(), lower); + let mut set = HashSet::with_capacity_and_hasher(lower, Default::default()); set.extend(iter); set } diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index 4db91346402..2d86734e569 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -192,7 +192,7 @@ impl< fn decode(d: &mut D) -> HashMap { d.read_map(|d, len| { let hasher = Default::default(); - let mut map = HashMap::with_capacity_and_hasher(hasher, len); + let mut map = HashMap::with_capacity_and_hasher(len, hasher); for i in range(0u, len) { let key = d.read_map_elt_key(i, |d| Decodable::decode(d)); let val = d.read_map_elt_val(i, |d| Decodable::decode(d)); @@ -228,7 +228,7 @@ impl< > Decodable for HashSet { fn decode(d: &mut D) -> HashSet { d.read_seq(|d, len| { - let mut set = HashSet::with_capacity_and_hasher(Default::default(), len); + let mut set = HashSet::with_capacity_and_hasher(len, Default::default()); for i in range(0u, len) { set.insert(d.read_seq_elt(i, |d| Decodable::decode(d))); }