@@ -16,15 +16,13 @@ use collections::{Collection, Mutable, Set, MutableSet, Map, MutableMap};
1616use default:: Default ;
1717use fmt:: Show ;
1818use fmt;
19- use hash:: { Hash , Hasher , sip } ;
19+ use hash:: { Hash , Hasher , RandomSipHasher } ;
2020use iter:: { Iterator , FilterMap , Chain , Repeat , Zip , Extendable } ;
2121use iter:: { range, range_inclusive, FromIterator } ;
2222use iter;
2323use mem:: replace;
2424use num;
2525use option:: { Some , None , Option } ;
26- use rand:: Rng ;
27- use rand;
2826use result:: { Ok , Err } ;
2927
3028mod table {
@@ -733,7 +731,7 @@ impl DefaultResizePolicy {
733731/// }
734732/// ```
735733#[ deriving( Clone ) ]
736- pub struct HashMap < K , V , H = sip :: SipHasher > {
734+ pub struct HashMap < K , V , H = RandomSipHasher > {
737735 // All hashes are keyed on these values, to prevent hash collision attacks.
738736 hasher : H ,
739737
@@ -1033,18 +1031,17 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> MutableMap<K, V> for HashMap<K, V, H>
10331031
10341032}
10351033
1036- impl < K : Hash + Eq , V > HashMap < K , V , sip :: SipHasher > {
1034+ impl < K : Hash + Eq , V > HashMap < K , V , RandomSipHasher > {
10371035 /// Create an empty HashMap.
1038- pub fn new ( ) -> HashMap < K , V , sip:: SipHasher > {
1036+ #[ inline]
1037+ pub fn new ( ) -> HashMap < K , V , RandomSipHasher > {
10391038 HashMap :: with_capacity ( INITIAL_CAPACITY )
10401039 }
10411040
10421041 /// Creates an empty hash map with the given initial capacity.
1043- pub fn with_capacity ( capacity : uint ) -> HashMap < K , V , sip:: SipHasher > {
1044- let mut r = rand:: task_rng ( ) ;
1045- let r0 = r. gen ( ) ;
1046- let r1 = r. gen ( ) ;
1047- let hasher = sip:: SipHasher :: new_with_keys ( r0, r1) ;
1042+ #[ inline]
1043+ pub fn with_capacity ( capacity : uint ) -> HashMap < K , V , RandomSipHasher > {
1044+ let hasher = RandomSipHasher :: new ( ) ;
10481045 HashMap :: with_capacity_and_hasher ( capacity, hasher)
10491046 }
10501047}
@@ -1053,6 +1050,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
10531050 /// Creates an empty hashmap which will use the given hasher to hash keys.
10541051 ///
10551052 /// The creates map has the default initial capacity.
1053+ #[ inline]
10561054 pub fn with_hasher ( hasher : H ) -> HashMap < K , V , H > {
10571055 HashMap :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher)
10581056 }
@@ -1064,6 +1062,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
10641062 /// is designed to allow HashMaps to be resistant to attacks that
10651063 /// cause many collisions and very poor performance. Setting it
10661064 /// manually using this function can expose a DoS attack vector.
1065+ #[ inline]
10671066 pub fn with_capacity_and_hasher ( capacity : uint , hasher : H ) -> HashMap < K , V , H > {
10681067 let cap = num:: next_power_of_two ( max ( INITIAL_CAPACITY , capacity) ) ;
10691068 HashMap {
@@ -1489,7 +1488,7 @@ pub type SetMoveItems<K> =
14891488/// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
14901489/// requires that the elements implement the `Eq` and `Hash` traits.
14911490#[ deriving( Clone ) ]
1492- pub struct HashSet < T , H = sip :: SipHasher > {
1491+ pub struct HashSet < T , H = RandomSipHasher > {
14931492 map : HashMap < T , ( ) , H >
14941493}
14951494
@@ -1529,15 +1528,17 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> MutableSet<T> for HashSet<T, H> {
15291528 fn remove ( & mut self , value : & T ) -> bool { self . map . remove ( value) }
15301529}
15311530
1532- impl < T : Hash + Eq > HashSet < T , sip :: SipHasher > {
1531+ impl < T : Hash + Eq > HashSet < T , RandomSipHasher > {
15331532 /// Create an empty HashSet
1534- pub fn new ( ) -> HashSet < T , sip:: SipHasher > {
1533+ #[ inline]
1534+ pub fn new ( ) -> HashSet < T , RandomSipHasher > {
15351535 HashSet :: with_capacity ( INITIAL_CAPACITY )
15361536 }
15371537
15381538 /// Create an empty HashSet with space for at least `n` elements in
15391539 /// the hash table.
1540- pub fn with_capacity ( capacity : uint ) -> HashSet < T , sip:: SipHasher > {
1540+ #[ inline]
1541+ pub fn with_capacity ( capacity : uint ) -> HashSet < T , RandomSipHasher > {
15411542 HashSet { map : HashMap :: with_capacity ( capacity) }
15421543 }
15431544}
@@ -1547,6 +1548,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
15471548 /// keys.
15481549 ///
15491550 /// The hash set is also created with the default initial capacity.
1551+ #[ inline]
15501552 pub fn with_hasher ( hasher : H ) -> HashSet < T , H > {
15511553 HashSet :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher)
15521554 }
@@ -1558,6 +1560,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
15581560 /// is designed to allow `HashSet`s to be resistant to attacks that
15591561 /// cause many collisions and very poor performance. Setting it
15601562 /// manually using this function can expose a DoS attack vector.
1563+ #[ inline]
15611564 pub fn with_capacity_and_hasher ( capacity : uint , hasher : H ) -> HashSet < T , H > {
15621565 HashSet { map : HashMap :: with_capacity_and_hasher ( capacity, hasher) }
15631566 }
0 commit comments