12
12
13
13
use std:: container:: { Container , Mutable , Map , MutableMap , Set , MutableSet } ;
14
14
use std:: clone:: Clone ;
15
- use std:: cmp:: { Eq , Equiv , max} ;
15
+ use std:: cmp:: { Eq , TotalEq , Equiv , max} ;
16
16
use std:: default:: Default ;
17
17
use std:: fmt;
18
18
use std:: fmt:: Show ;
@@ -140,6 +140,7 @@ mod table {
140
140
}
141
141
142
142
/// A hash that is not zero, since we use that to represent empty buckets.
143
+ #[ deriving( Eq ) ]
143
144
pub struct SafeHash {
144
145
priv hash : u64 ,
145
146
}
@@ -149,10 +150,6 @@ mod table {
149
150
pub fn inspect ( & self ) -> u64 { self . hash }
150
151
}
151
152
152
- impl Eq for SafeHash {
153
- fn eq ( & self , other : & SafeHash ) -> bool { self . hash == other. hash }
154
- }
155
-
156
153
/// We need to remove hashes of 0. That's reserved for empty buckets.
157
154
/// This function wraps up `hash_keyed` to be the only way outside this
158
155
/// module to generate a SafeHash.
@@ -698,7 +695,7 @@ fn grow_at(capacity: uint, load_factor: Fraction) -> uint {
698
695
fraction_mul ( capacity, load_factor)
699
696
}
700
697
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 > {
702
699
/// Get the number of elements which will force the capacity to shrink.
703
700
/// When size == self.shrink_at(), we halve the capacity.
704
701
fn shrink_at ( & self ) -> uint {
@@ -799,12 +796,12 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
799
796
}
800
797
}
801
798
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 > {
803
800
/// Return the number of elements in the map
804
801
fn len ( & self ) -> uint { self . table . size ( ) }
805
802
}
806
803
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 > {
808
805
/// Clear the map, removing all key-value pairs.
809
806
fn clear ( & mut self ) {
810
807
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> {
819
816
}
820
817
821
818
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 > {
823
820
fn find < ' a > ( & ' a self , k : & K ) -> Option < & ' a V > {
824
821
self . search ( k) . map ( |idx| {
825
822
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> {
832
829
}
833
830
}
834
831
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 > {
836
833
fn find_mut < ' a > ( & ' a mut self , k : & K ) -> Option < & ' a mut V > {
837
834
match self . search ( k) {
838
835
None => None ,
@@ -969,7 +966,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> MutableMap<K, V> for HashMap<K, V, H>
969
966
}
970
967
}
971
968
972
- impl < K : Hash + Eq , V > HashMap < K , V , sip:: SipHasher > {
969
+ impl < K : Hash + TotalEq , V > HashMap < K , V , sip:: SipHasher > {
973
970
/// Create an empty HashMap.
974
971
pub fn new ( ) -> HashMap < K , V , sip:: SipHasher > {
975
972
HashMap :: with_capacity ( INITIAL_CAPACITY )
@@ -984,7 +981,7 @@ impl<K: Hash + Eq, V> HashMap<K, V, sip::SipHasher> {
984
981
}
985
982
}
986
983
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 > {
988
985
pub fn with_hasher ( hasher : H ) -> HashMap < K , V , H > {
989
986
HashMap :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher)
990
987
}
@@ -1296,7 +1293,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
1296
1293
}
1297
1294
}
1298
1295
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 > {
1300
1297
/// Like `find`, but returns a copy of the value.
1301
1298
pub fn find_copy ( & self , k : & K ) -> Option < V > {
1302
1299
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> {
1308
1305
}
1309
1306
}
1310
1307
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 > {
1312
1309
fn eq ( & self , other : & HashMap < K , V , H > ) -> bool {
1313
1310
if self . len ( ) != other. len ( ) { return false ; }
1314
1311
@@ -1321,7 +1318,7 @@ impl<K: Eq + Hash<S>, V: Eq, S, H: Hasher<S>> Eq for HashMap<K, V, H> {
1321
1318
}
1322
1319
}
1323
1320
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 > {
1325
1322
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1326
1323
try!( write ! ( f. buf, r"\{" ) ) ;
1327
1324
@@ -1334,7 +1331,7 @@ impl<K: Eq + Hash<S> + Show, V: Show, S, H: Hasher<S>> Show for HashMap<K, V, H>
1334
1331
}
1335
1332
}
1336
1333
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 > {
1338
1335
fn default ( ) -> HashMap < K , V , H > {
1339
1336
HashMap :: with_capacity_and_hasher ( INITIAL_CAPACITY , Default :: default ( ) )
1340
1337
}
@@ -1358,7 +1355,7 @@ pub type Keys<'a, K, V> =
1358
1355
pub type Values < ' a , K , V > =
1359
1356
iter:: Map < ' static , ( & ' a K , & ' a V ) , & ' a V , Entries < ' a , K , V > > ;
1360
1357
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 > {
1362
1359
fn from_iterator < T : Iterator < ( K , V ) > > ( iter : & mut T ) -> HashMap < K , V , H > {
1363
1360
let ( lower, _) = iter. size_hint ( ) ;
1364
1361
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
1367
1364
}
1368
1365
}
1369
1366
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 > {
1371
1368
fn extend < T : Iterator < ( K , V ) > > ( & mut self , iter : & mut T ) {
1372
1369
for ( k, v) in * iter {
1373
1370
self . insert ( k, v) ;
@@ -1391,7 +1388,7 @@ pub struct HashSet<T, H = sip::SipHasher> {
1391
1388
priv map: HashMap < T , ( ) , H >
1392
1389
}
1393
1390
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 > {
1395
1392
// FIXME #11998: Since the value is a (), and `find` returns a Some(&()),
1396
1393
// we trigger #11998 when matching on it. I've fallen back to manual
1397
1394
// iteration until this is fixed.
@@ -1402,17 +1399,17 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> Eq for HashSet<T, H> {
1402
1399
}
1403
1400
}
1404
1401
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 > {
1406
1403
/// Return the number of elements in the set
1407
1404
fn len ( & self ) -> uint { self . map . len ( ) }
1408
1405
}
1409
1406
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 > {
1411
1408
/// Clear the set, removing all values.
1412
1409
fn clear ( & mut self ) { self . map . clear ( ) }
1413
1410
}
1414
1411
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 > {
1416
1413
/// Return true if the set contains a value
1417
1414
fn contains ( & self , value : & T ) -> bool { self . map . search ( value) . is_some ( ) }
1418
1415
@@ -1433,7 +1430,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> Set<T> for HashSet<T, H> {
1433
1430
}
1434
1431
}
1435
1432
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 > {
1437
1434
/// Add a value to the set. Return true if the value was not already
1438
1435
/// present in the set.
1439
1436
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> {
1443
1440
fn remove ( & mut self , value : & T ) -> bool { self . map . remove ( value) }
1444
1441
}
1445
1442
1446
- impl < T : Hash + Eq > HashSet < T , sip:: SipHasher > {
1443
+ impl < T : Hash + TotalEq > HashSet < T , sip:: SipHasher > {
1447
1444
/// Create an empty HashSet
1448
1445
pub fn new ( ) -> HashSet < T , sip:: SipHasher > {
1449
1446
HashSet :: with_capacity ( INITIAL_CAPACITY )
@@ -1456,7 +1453,7 @@ impl<T: Hash + Eq> HashSet<T, sip::SipHasher> {
1456
1453
}
1457
1454
}
1458
1455
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 > {
1460
1457
pub fn with_hasher ( hasher : H ) -> HashSet < T , H > {
1461
1458
HashSet :: with_capacity_and_hasher ( INITIAL_CAPACITY , hasher)
1462
1459
}
@@ -1529,7 +1526,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1529
1526
1530
1527
}
1531
1528
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 > {
1533
1530
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1534
1531
try!( write ! ( f. buf, r"\{" ) ) ;
1535
1532
@@ -1542,7 +1539,7 @@ impl<T: Eq + Hash<S> + fmt::Show, S, H: Hasher<S>> fmt::Show for HashSet<T, H> {
1542
1539
}
1543
1540
}
1544
1541
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 > {
1546
1543
fn from_iterator < I : Iterator < T > > ( iter : & mut I ) -> HashSet < T , H > {
1547
1544
let ( lower, _) = iter. size_hint ( ) ;
1548
1545
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,
1551
1548
}
1552
1549
}
1553
1550
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 > {
1555
1552
fn extend < I : Iterator < T > > ( & mut self , iter : & mut I ) {
1556
1553
for k in * iter {
1557
1554
self . insert ( k) ;
1558
1555
}
1559
1556
}
1560
1557
}
1561
1558
1562
- impl < T : Eq + Hash > Default for HashSet < T , sip:: SipHasher > {
1559
+ impl < T : TotalEq + Hash > Default for HashSet < T , sip:: SipHasher > {
1563
1560
fn default ( ) -> HashSet < T > { HashSet :: new ( ) }
1564
1561
}
1565
1562
@@ -1601,7 +1598,7 @@ mod test_map {
1601
1598
1602
1599
local_data_key ! ( drop_vector: vec:: Vec <int>)
1603
1600
1604
- #[ deriving( Hash , Eq ) ]
1601
+ #[ deriving( Hash , Eq , TotalEq ) ]
1605
1602
struct Dropable {
1606
1603
k : int
1607
1604
}
0 commit comments