@@ -337,7 +337,9 @@ impl<T, S> HashSet<T, S>
337
337
/// assert_eq!(diff, [4].iter().collect());
338
338
/// ```
339
339
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
340
- pub fn difference < ' a > ( & ' a self , other : & ' a HashSet < T , S > ) -> Difference < ' a , T , S > {
340
+ pub fn difference < ' a , U : BuildHasher > ( & ' a self ,
341
+ other : & ' a HashSet < T , U > )
342
+ -> Difference < ' a , T , U > {
341
343
Difference {
342
344
iter : self . iter ( ) ,
343
345
other,
@@ -391,7 +393,9 @@ impl<T, S> HashSet<T, S>
391
393
/// assert_eq!(intersection, [2, 3].iter().collect());
392
394
/// ```
393
395
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
394
- pub fn intersection < ' a > ( & ' a self , other : & ' a HashSet < T , S > ) -> Intersection < ' a , T , S > {
396
+ pub fn intersection < ' a , U : BuildHasher > ( & ' a self ,
397
+ other : & ' a HashSet < T , U > )
398
+ -> Intersection < ' a , T , U > {
395
399
Intersection {
396
400
iter : self . iter ( ) ,
397
401
other,
@@ -565,7 +569,7 @@ impl<T, S> HashSet<T, S>
565
569
/// assert_eq!(a.is_disjoint(&b), false);
566
570
/// ```
567
571
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
568
- pub fn is_disjoint ( & self , other : & HashSet < T , S > ) -> bool {
572
+ pub fn is_disjoint < U : BuildHasher > ( & self , other : & HashSet < T , U > ) -> bool {
569
573
self . iter ( ) . all ( |v| !other. contains ( v) )
570
574
}
571
575
@@ -587,7 +591,7 @@ impl<T, S> HashSet<T, S>
587
591
/// assert_eq!(set.is_subset(&sup), false);
588
592
/// ```
589
593
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
590
- pub fn is_subset ( & self , other : & HashSet < T , S > ) -> bool {
594
+ pub fn is_subset < U : BuildHasher > ( & self , other : & HashSet < T , U > ) -> bool {
591
595
self . iter ( ) . all ( |v| other. contains ( v) )
592
596
}
593
597
@@ -613,7 +617,7 @@ impl<T, S> HashSet<T, S>
613
617
/// ```
614
618
#[ inline]
615
619
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
616
- pub fn is_superset ( & self , other : & HashSet < T , S > ) -> bool {
620
+ pub fn is_superset < U : BuildHasher > ( & self , other : & HashSet < T , U > ) -> bool {
617
621
other. is_subset ( self )
618
622
}
619
623
@@ -1375,6 +1379,23 @@ fn assert_covariance() {
1375
1379
mod test_set {
1376
1380
use super :: HashSet ;
1377
1381
use super :: super :: map:: RandomState ;
1382
+ use hash:: BuildHasher ;
1383
+
1384
+ struct AltRandomState ( RandomState ) ;
1385
+
1386
+ impl AltRandomState {
1387
+ fn new ( ) -> AltRandomState {
1388
+ AltRandomState ( RandomState :: new ( ) )
1389
+ }
1390
+ }
1391
+
1392
+ impl BuildHasher for AltRandomState {
1393
+ type Hasher = <RandomState as BuildHasher >:: Hasher ;
1394
+
1395
+ fn build_hasher ( & self ) -> Self :: Hasher {
1396
+ self . 0 . build_hasher ( )
1397
+ }
1398
+ }
1378
1399
1379
1400
#[ test]
1380
1401
fn test_zero_capacities ( ) {
@@ -1410,8 +1431,8 @@ mod test_set {
1410
1431
1411
1432
#[ test]
1412
1433
fn test_disjoint ( ) {
1413
- let mut xs = HashSet :: new ( ) ;
1414
- let mut ys = HashSet :: new ( ) ;
1434
+ let mut xs = HashSet :: with_hasher ( RandomState :: new ( ) ) ;
1435
+ let mut ys = HashSet :: with_hasher ( AltRandomState :: new ( ) ) ;
1415
1436
assert ! ( xs. is_disjoint( & ys) ) ;
1416
1437
assert ! ( ys. is_disjoint( & xs) ) ;
1417
1438
assert ! ( xs. insert( 5 ) ) ;
@@ -1432,13 +1453,13 @@ mod test_set {
1432
1453
1433
1454
#[ test]
1434
1455
fn test_subset_and_superset ( ) {
1435
- let mut a = HashSet :: new ( ) ;
1456
+ let mut a = HashSet :: with_hasher ( RandomState :: new ( ) ) ;
1436
1457
assert ! ( a. insert( 0 ) ) ;
1437
1458
assert ! ( a. insert( 5 ) ) ;
1438
1459
assert ! ( a. insert( 11 ) ) ;
1439
1460
assert ! ( a. insert( 7 ) ) ;
1440
1461
1441
- let mut b = HashSet :: new ( ) ;
1462
+ let mut b = HashSet :: with_hasher ( AltRandomState :: new ( ) ) ;
1442
1463
assert ! ( b. insert( 0 ) ) ;
1443
1464
assert ! ( b. insert( 7 ) ) ;
1444
1465
assert ! ( b. insert( 19 ) ) ;
@@ -1474,8 +1495,8 @@ mod test_set {
1474
1495
1475
1496
#[ test]
1476
1497
fn test_intersection ( ) {
1477
- let mut a = HashSet :: new ( ) ;
1478
- let mut b = HashSet :: new ( ) ;
1498
+ let mut a = HashSet :: with_hasher ( RandomState :: new ( ) ) ;
1499
+ let mut b = HashSet :: with_hasher ( AltRandomState :: new ( ) ) ;
1479
1500
1480
1501
assert ! ( a. insert( 11 ) ) ;
1481
1502
assert ! ( a. insert( 1 ) ) ;
@@ -1504,8 +1525,8 @@ mod test_set {
1504
1525
1505
1526
#[ test]
1506
1527
fn test_difference ( ) {
1507
- let mut a = HashSet :: new ( ) ;
1508
- let mut b = HashSet :: new ( ) ;
1528
+ let mut a = HashSet :: with_hasher ( RandomState :: new ( ) ) ;
1529
+ let mut b = HashSet :: with_hasher ( AltRandomState :: new ( ) ) ;
1509
1530
1510
1531
assert ! ( a. insert( 1 ) ) ;
1511
1532
assert ! ( a. insert( 3 ) ) ;
0 commit comments