@@ -16,15 +16,13 @@ use collections::{Collection, Mutable, Set, MutableSet, Map, MutableMap};
16
16
use default:: Default ;
17
17
use fmt:: Show ;
18
18
use fmt;
19
- use hash:: { Hash , Hasher , sip } ;
19
+ use hash:: { Hash , Hasher , RandomSipHasher } ;
20
20
use iter:: { Iterator , FilterMap , Chain , Repeat , Zip , Extendable } ;
21
21
use iter:: { range, range_inclusive, FromIterator } ;
22
22
use iter;
23
23
use mem:: replace;
24
24
use num;
25
25
use option:: { Some , None , Option } ;
26
- use rand:: Rng ;
27
- use rand;
28
26
use result:: { Ok , Err } ;
29
27
30
28
mod table {
@@ -733,7 +731,7 @@ impl DefaultResizePolicy {
733
731
/// }
734
732
/// ```
735
733
#[ deriving( Clone ) ]
736
- pub struct HashMap < K , V , H = sip :: SipHasher > {
734
+ pub struct HashMap < K , V , H = RandomSipHasher > {
737
735
// All hashes are keyed on these values, to prevent hash collision attacks.
738
736
hasher : H ,
739
737
@@ -1033,18 +1031,17 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> MutableMap<K, V> for HashMap<K, V, H>
1033
1031
1034
1032
}
1035
1033
1036
- impl < K : Hash + Eq , V > HashMap < K , V , sip :: SipHasher > {
1034
+ impl < K : Hash + Eq , V > HashMap < K , V , RandomSipHasher > {
1037
1035
/// Create an empty HashMap.
1038
- pub fn new ( ) -> HashMap < K , V , sip:: SipHasher > {
1036
+ #[ inline]
1037
+ pub fn new ( ) -> HashMap < K , V , RandomSipHasher > {
1039
1038
HashMap :: with_capacity ( INITIAL_CAPACITY )
1040
1039
}
1041
1040
1042
1041
/// 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 ( ) ;
1048
1045
HashMap :: with_capacity_and_hasher ( capacity, hasher)
1049
1046
}
1050
1047
}
@@ -1053,6 +1050,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1053
1050
/// Creates an empty hashmap which will use the given hasher to hash keys.
1054
1051
///
1055
1052
/// The creates map has the default initial capacity.
1053
+ #[ inline]
1056
1054
pub fn with_hasher ( hasher : H ) -> HashMap < K , V , H > {
1057
1055
HashMap :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher)
1058
1056
}
@@ -1064,6 +1062,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1064
1062
/// is designed to allow HashMaps to be resistant to attacks that
1065
1063
/// cause many collisions and very poor performance. Setting it
1066
1064
/// manually using this function can expose a DoS attack vector.
1065
+ #[ inline]
1067
1066
pub fn with_capacity_and_hasher ( capacity : uint , hasher : H ) -> HashMap < K , V , H > {
1068
1067
let cap = num:: next_power_of_two ( max ( INITIAL_CAPACITY , capacity) ) ;
1069
1068
HashMap {
@@ -1489,7 +1488,7 @@ pub type SetMoveItems<K> =
1489
1488
/// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
1490
1489
/// requires that the elements implement the `Eq` and `Hash` traits.
1491
1490
#[ deriving( Clone ) ]
1492
- pub struct HashSet < T , H = sip :: SipHasher > {
1491
+ pub struct HashSet < T , H = RandomSipHasher > {
1493
1492
map : HashMap < T , ( ) , H >
1494
1493
}
1495
1494
@@ -1529,15 +1528,17 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> MutableSet<T> for HashSet<T, H> {
1529
1528
fn remove ( & mut self , value : & T ) -> bool { self . map . remove ( value) }
1530
1529
}
1531
1530
1532
- impl < T : Hash + Eq > HashSet < T , sip :: SipHasher > {
1531
+ impl < T : Hash + Eq > HashSet < T , RandomSipHasher > {
1533
1532
/// Create an empty HashSet
1534
- pub fn new ( ) -> HashSet < T , sip:: SipHasher > {
1533
+ #[ inline]
1534
+ pub fn new ( ) -> HashSet < T , RandomSipHasher > {
1535
1535
HashSet :: with_capacity ( INITIAL_CAPACITY )
1536
1536
}
1537
1537
1538
1538
/// Create an empty HashSet with space for at least `n` elements in
1539
1539
/// 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 > {
1541
1542
HashSet { map : HashMap :: with_capacity ( capacity) }
1542
1543
}
1543
1544
}
@@ -1547,6 +1548,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1547
1548
/// keys.
1548
1549
///
1549
1550
/// The hash set is also created with the default initial capacity.
1551
+ #[ inline]
1550
1552
pub fn with_hasher ( hasher : H ) -> HashSet < T , H > {
1551
1553
HashSet :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher)
1552
1554
}
@@ -1558,6 +1560,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1558
1560
/// is designed to allow `HashSet`s to be resistant to attacks that
1559
1561
/// cause many collisions and very poor performance. Setting it
1560
1562
/// manually using this function can expose a DoS attack vector.
1563
+ #[ inline]
1561
1564
pub fn with_capacity_and_hasher ( capacity : uint , hasher : H ) -> HashSet < T , H > {
1562
1565
HashSet { map : HashMap :: with_capacity_and_hasher ( capacity, hasher) }
1563
1566
}
0 commit comments