1212
1313use std:: container:: { Container , Mutable , Map , MutableMap , Set , MutableSet } ;
1414use std:: clone:: Clone ;
15- use std:: cmp:: { Eq , Equiv , max} ;
15+ use std:: cmp:: { Eq , TotalEq , Equiv , max} ;
1616use std:: default:: Default ;
1717use std:: fmt;
1818use std:: fmt:: Show ;
@@ -140,6 +140,7 @@ mod table {
140140 }
141141
142142 /// A hash that is not zero, since we use that to represent empty buckets.
143+ #[ deriving( Eq ) ]
143144 pub struct SafeHash {
144145 priv hash : u64 ,
145146 }
@@ -149,10 +150,6 @@ mod table {
149150 pub fn inspect ( & self ) -> u64 { self . hash }
150151 }
151152
152- impl Eq for SafeHash {
153- fn eq ( & self , other : & SafeHash ) -> bool { self . hash == other. hash }
154- }
155-
156153 /// We need to remove hashes of 0. That's reserved for empty buckets.
157154 /// This function wraps up `hash_keyed` to be the only way outside this
158155 /// module to generate a SafeHash.
@@ -698,7 +695,7 @@ fn grow_at(capacity: uint, load_factor: Fraction) -> uint {
698695 fraction_mul ( capacity, load_factor)
699696}
700697
701- impl < K : Eq + Hash < S > , V , S , H : Hasher < S > > HashMap < K , V , H > {
698+ impl < K : TotalEq + Hash < S > , V , S , H : Hasher < S > > HashMap < K , V , H > {
702699 /// Get the number of elements which will force the capacity to shrink.
703700 /// When size == self.shrink_at(), we halve the capacity.
704701 fn shrink_at ( & self ) -> uint {
@@ -799,12 +796,12 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
799796 }
800797}
801798
802- impl < K : Eq + Hash < S > , V , S , H : Hasher < S > > Container for HashMap < K , V , H > {
799+ impl < K : TotalEq + Hash < S > , V , S , H : Hasher < S > > Container for HashMap < K , V , H > {
803800 /// Return the number of elements in the map
804801 fn len ( & self ) -> uint { self . table . size ( ) }
805802}
806803
807- impl < K : Eq + Hash < S > , V , S , H : Hasher < S > > Mutable for HashMap < K , V , H > {
804+ impl < K : TotalEq + Hash < S > , V , S , H : Hasher < S > > Mutable for HashMap < K , V , H > {
808805 /// Clear the map, removing all key-value pairs.
809806 fn clear ( & mut self ) {
810807 self . minimum_capacity = self . table . size ( ) ;
@@ -819,7 +816,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> Mutable for HashMap<K, V, H> {
819816}
820817
821818
822- impl < K : Eq + Hash < S > , V , S , H : Hasher < S > > Map < K , V > for HashMap < K , V , H > {
819+ impl < K : TotalEq + Hash < S > , V , S , H : Hasher < S > > Map < K , V > for HashMap < K , V , H > {
823820 fn find < ' a > ( & ' a self , k : & K ) -> Option < & ' a V > {
824821 self . search ( k) . map ( |idx| {
825822 let ( _, v) = self . table . read ( & idx) ;
@@ -832,7 +829,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> Map<K, V> for HashMap<K, V, H> {
832829 }
833830}
834831
835- impl < K : Eq + Hash < S > , V , S , H : Hasher < S > > MutableMap < K , V > for HashMap < K , V , H > {
832+ impl < K : TotalEq + Hash < S > , V , S , H : Hasher < S > > MutableMap < K , V > for HashMap < K , V , H > {
836833 fn find_mut < ' a > ( & ' a mut self , k : & K ) -> Option < & ' a mut V > {
837834 match self . search ( k) {
838835 None => None ,
@@ -969,7 +966,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> MutableMap<K, V> for HashMap<K, V, H>
969966 }
970967}
971968
972- impl < K : Hash + Eq , V > HashMap < K , V , sip:: SipHasher > {
969+ impl < K : Hash + TotalEq , V > HashMap < K , V , sip:: SipHasher > {
973970 /// Create an empty HashMap.
974971 pub fn new ( ) -> HashMap < K , V , sip:: SipHasher > {
975972 HashMap :: with_capacity ( INITIAL_CAPACITY )
@@ -984,7 +981,7 @@ impl<K: Hash + Eq, V> HashMap<K, V, sip::SipHasher> {
984981 }
985982}
986983
987- impl < K : Eq + Hash < S > , V , S , H : Hasher < S > > HashMap < K , V , H > {
984+ impl < K : TotalEq + Hash < S > , V , S , H : Hasher < S > > HashMap < K , V , H > {
988985 pub fn with_hasher ( hasher : H ) -> HashMap < K , V , H > {
989986 HashMap :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher)
990987 }
@@ -1296,7 +1293,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
12961293 }
12971294}
12981295
1299- impl < K : Eq + Hash < S > , V : Clone , S , H : Hasher < S > > HashMap < K , V , H > {
1296+ impl < K : TotalEq + Hash < S > , V : Clone , S , H : Hasher < S > > HashMap < K , V , H > {
13001297 /// Like `find`, but returns a copy of the value.
13011298 pub fn find_copy ( & self , k : & K ) -> Option < V > {
13021299 self . find ( k) . map ( |v| ( * v) . clone ( ) )
@@ -1308,7 +1305,7 @@ impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> {
13081305 }
13091306}
13101307
1311- impl < K : Eq + Hash < S > , V : Eq , S , H : Hasher < S > > Eq for HashMap < K , V , H > {
1308+ impl < K : TotalEq + Hash < S > , V : Eq , S , H : Hasher < S > > Eq for HashMap < K , V , H > {
13121309 fn eq ( & self , other : & HashMap < K , V , H > ) -> bool {
13131310 if self . len ( ) != other. len ( ) { return false ; }
13141311
@@ -1321,7 +1318,7 @@ impl<K: Eq + Hash<S>, V: Eq, S, H: Hasher<S>> Eq for HashMap<K, V, H> {
13211318 }
13221319}
13231320
1324- impl < K : Eq + Hash < S > + Show , V : Show , S , H : Hasher < S > > Show for HashMap < K , V , H > {
1321+ impl < K : TotalEq + Hash < S > + Show , V : Show , S , H : Hasher < S > > Show for HashMap < K , V , H > {
13251322 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
13261323 try!( write ! ( f. buf, r"\{" ) ) ;
13271324
@@ -1334,7 +1331,7 @@ impl<K: Eq + Hash<S> + Show, V: Show, S, H: Hasher<S>> Show for HashMap<K, V, H>
13341331 }
13351332}
13361333
1337- impl < K : Eq + Hash < S > , V , S , H : Hasher < S > + Default > Default for HashMap < K , V , H > {
1334+ impl < K : TotalEq + Hash < S > , V , S , H : Hasher < S > + Default > Default for HashMap < K , V , H > {
13381335 fn default ( ) -> HashMap < K , V , H > {
13391336 HashMap :: with_capacity_and_hasher ( INITIAL_CAPACITY , Default :: default ( ) )
13401337 }
@@ -1358,7 +1355,7 @@ pub type Keys<'a, K, V> =
13581355pub type Values < ' a , K , V > =
13591356 iter:: Map < ' static , ( & ' a K , & ' a V ) , & ' a V , Entries < ' a , K , V > > ;
13601357
1361- impl < K : Eq + Hash < S > , V , S , H : Hasher < S > + Default > FromIterator < ( K , V ) > for HashMap < K , V , H > {
1358+ impl < K : TotalEq + Hash < S > , V , S , H : Hasher < S > + Default > FromIterator < ( K , V ) > for HashMap < K , V , H > {
13621359 fn from_iterator < T : Iterator < ( K , V ) > > ( iter : & mut T ) -> HashMap < K , V , H > {
13631360 let ( lower, _) = iter. size_hint ( ) ;
13641361 let mut map = HashMap :: with_capacity_and_hasher ( lower, Default :: default ( ) ) ;
@@ -1367,7 +1364,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> FromIterator<(K, V)> for Has
13671364 }
13681365}
13691366
1370- impl < K : Eq + Hash < S > , V , S , H : Hasher < S > + Default > Extendable < ( K , V ) > for HashMap < K , V , H > {
1367+ impl < K : TotalEq + Hash < S > , V , S , H : Hasher < S > + Default > Extendable < ( K , V ) > for HashMap < K , V , H > {
13711368 fn extend < T : Iterator < ( K , V ) > > ( & mut self , iter : & mut T ) {
13721369 for ( k, v) in * iter {
13731370 self . insert ( k, v) ;
@@ -1391,7 +1388,7 @@ pub struct HashSet<T, H = sip::SipHasher> {
13911388 priv map: HashMap < T , ( ) , H >
13921389}
13931390
1394- impl < T : Eq + Hash < S > , S , H : Hasher < S > > Eq for HashSet < T , H > {
1391+ impl < T : TotalEq + Hash < S > , S , H : Hasher < S > > Eq for HashSet < T , H > {
13951392 // FIXME #11998: Since the value is a (), and `find` returns a Some(&()),
13961393 // we trigger #11998 when matching on it. I've fallen back to manual
13971394 // iteration until this is fixed.
@@ -1402,17 +1399,17 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> Eq for HashSet<T, H> {
14021399 }
14031400}
14041401
1405- impl < T : Eq + Hash < S > , S , H : Hasher < S > > Container for HashSet < T , H > {
1402+ impl < T : TotalEq + Hash < S > , S , H : Hasher < S > > Container for HashSet < T , H > {
14061403 /// Return the number of elements in the set
14071404 fn len ( & self ) -> uint { self . map . len ( ) }
14081405}
14091406
1410- impl < T : Eq + Hash < S > , S , H : Hasher < S > > Mutable for HashSet < T , H > {
1407+ impl < T : TotalEq + Hash < S > , S , H : Hasher < S > > Mutable for HashSet < T , H > {
14111408 /// Clear the set, removing all values.
14121409 fn clear ( & mut self ) { self . map . clear ( ) }
14131410}
14141411
1415- impl < T : Eq + Hash < S > , S , H : Hasher < S > > Set < T > for HashSet < T , H > {
1412+ impl < T : TotalEq + Hash < S > , S , H : Hasher < S > > Set < T > for HashSet < T , H > {
14161413 /// Return true if the set contains a value
14171414 fn contains ( & self , value : & T ) -> bool { self . map . search ( value) . is_some ( ) }
14181415
@@ -1433,7 +1430,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> Set<T> for HashSet<T, H> {
14331430 }
14341431}
14351432
1436- impl < T : Eq + Hash < S > , S , H : Hasher < S > > MutableSet < T > for HashSet < T , H > {
1433+ impl < T : TotalEq + Hash < S > , S , H : Hasher < S > > MutableSet < T > for HashSet < T , H > {
14371434 /// Add a value to the set. Return true if the value was not already
14381435 /// present in the set.
14391436 fn insert ( & mut self , value : T ) -> bool { self . map . insert ( value, ( ) ) }
@@ -1443,7 +1440,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> MutableSet<T> for HashSet<T, H> {
14431440 fn remove ( & mut self , value : & T ) -> bool { self . map . remove ( value) }
14441441}
14451442
1446- impl < T : Hash + Eq > HashSet < T , sip:: SipHasher > {
1443+ impl < T : Hash + TotalEq > HashSet < T , sip:: SipHasher > {
14471444 /// Create an empty HashSet
14481445 pub fn new ( ) -> HashSet < T , sip:: SipHasher > {
14491446 HashSet :: with_capacity ( INITIAL_CAPACITY )
@@ -1456,7 +1453,7 @@ impl<T: Hash + Eq> HashSet<T, sip::SipHasher> {
14561453 }
14571454}
14581455
1459- impl < T : Eq + Hash < S > , S , H : Hasher < S > > HashSet < T , H > {
1456+ impl < T : TotalEq + Hash < S > , S , H : Hasher < S > > HashSet < T , H > {
14601457 pub fn with_hasher ( hasher : H ) -> HashSet < T , H > {
14611458 HashSet :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher)
14621459 }
@@ -1529,7 +1526,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
15291526
15301527}
15311528
1532- impl < T : Eq + Hash < S > + fmt:: Show , S , H : Hasher < S > > fmt:: Show for HashSet < T , H > {
1529+ impl < T : TotalEq + Hash < S > + fmt:: Show , S , H : Hasher < S > > fmt:: Show for HashSet < T , H > {
15331530 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
15341531 try!( write ! ( f. buf, r"\{" ) ) ;
15351532
@@ -1542,7 +1539,7 @@ impl<T: Eq + Hash<S> + fmt::Show, S, H: Hasher<S>> fmt::Show for HashSet<T, H> {
15421539 }
15431540}
15441541
1545- impl < T : Eq + Hash < S > , S , H : Hasher < S > + Default > FromIterator < T > for HashSet < T , H > {
1542+ impl < T : TotalEq + Hash < S > , S , H : Hasher < S > + Default > FromIterator < T > for HashSet < T , H > {
15461543 fn from_iterator < I : Iterator < T > > ( iter : & mut I ) -> HashSet < T , H > {
15471544 let ( lower, _) = iter. size_hint ( ) ;
15481545 let mut set = HashSet :: with_capacity_and_hasher ( lower, Default :: default ( ) ) ;
@@ -1551,15 +1548,15 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> FromIterator<T> for HashSet<T,
15511548 }
15521549}
15531550
1554- impl < T : Eq + Hash < S > , S , H : Hasher < S > + Default > Extendable < T > for HashSet < T , H > {
1551+ impl < T : TotalEq + Hash < S > , S , H : Hasher < S > + Default > Extendable < T > for HashSet < T , H > {
15551552 fn extend < I : Iterator < T > > ( & mut self , iter : & mut I ) {
15561553 for k in * iter {
15571554 self . insert ( k) ;
15581555 }
15591556 }
15601557}
15611558
1562- impl < T : Eq + Hash > Default for HashSet < T , sip:: SipHasher > {
1559+ impl < T : TotalEq + Hash > Default for HashSet < T , sip:: SipHasher > {
15631560 fn default ( ) -> HashSet < T > { HashSet :: new ( ) }
15641561}
15651562
@@ -1601,7 +1598,7 @@ mod test_map {
16011598
16021599 local_data_key ! ( drop_vector: vec:: Vec <int>)
16031600
1604- #[ deriving( Hash , Eq ) ]
1601+ #[ deriving( Hash , Eq , TotalEq ) ]
16051602 struct Dropable {
16061603 k : int
16071604 }
0 commit comments