@@ -1419,7 +1419,7 @@ pub trait Itertools: Iterator {
1419
1419
/// Setting it manually using this function can expose a DoS attack vector.
1420
1420
///
1421
1421
/// ```
1422
- /// use ahash ::RandomState;
1422
+ /// use std::hash ::RandomState;
1423
1423
/// use itertools::Itertools;
1424
1424
///
1425
1425
/// let data = vec![10, 20, 30, 20, 40, 10, 50];
@@ -1464,15 +1464,15 @@ pub trait Itertools: Iterator {
1464
1464
}
1465
1465
1466
1466
/// Return an iterator which yields the same elements as the one returned by
1467
- /// [.duplicates ()](crate::Itertools::duplicates ), but uses the specified hash builder to hash
1468
- /// the keys for comparison.
1467
+ /// [.duplicates_by ()](crate::Itertools::duplicates_by ), but uses the specified hash builder to
1468
+ /// hash the keys for comparison.
1469
1469
///
1470
1470
/// Warning: `hash_builder` is normally randomly generated, and is designed to allow it's
1471
1471
/// users to be resistant to attacks that cause many collisions and very poor performance.
1472
1472
/// Setting it manually using this function can expose a DoS attack vector.
1473
1473
///
1474
1474
/// ```
1475
- /// use ahash ::RandomState;
1475
+ /// use std::hash ::RandomState;
1476
1476
/// use itertools::Itertools;
1477
1477
///
1478
1478
/// let data = vec!["a", "bb", "aa", "c", "ccc"];
@@ -1518,7 +1518,33 @@ pub trait Itertools: Iterator {
1518
1518
Self : Sized ,
1519
1519
Self :: Item : Clone + Eq + Hash ,
1520
1520
{
1521
- unique_impl:: unique ( self )
1521
+ unique_impl:: unique_with_hasher ( self , RandomState :: new ( ) )
1522
+ }
1523
+
1524
+ /// Return an iterator which yields the same elements as the one returned by
1525
+ /// [.unique()](crate::Itertools::unique), but uses the specified hash builder to hash the
1526
+ /// elements for comparison.
1527
+ ///
1528
+ /// Warning: `hash_builder` is normally randomly generated, and is designed to allow it's
1529
+ /// users to be resistant to attacks that cause many collisions and very poor performance.
1530
+ /// Setting it manually using this function can expose a DoS attack vector.
1531
+ ///
1532
+ /// ```
1533
+ /// use std::hash::RandomState;
1534
+ /// use itertools::Itertools;
1535
+ ///
1536
+ /// let data = vec![10, 20, 30, 20, 40, 10, 50];
1537
+ /// itertools::assert_equal(data.into_iter().unique_with_hasher(RandomState::new()),
1538
+ /// vec![10, 20, 30, 40, 50]);
1539
+ /// ```
1540
+ #[ cfg( feature = "use_std" ) ]
1541
+ fn unique_with_hasher < S > ( self , hash_builder : S ) -> Unique < Self , S >
1542
+ where
1543
+ Self : Sized ,
1544
+ Self :: Item : Clone + Eq + Hash ,
1545
+ S : BuildHasher ,
1546
+ {
1547
+ unique_impl:: unique_with_hasher ( self , hash_builder)
1522
1548
}
1523
1549
1524
1550
/// Return an iterator adaptor that filters out elements that have
@@ -1546,7 +1572,34 @@ pub trait Itertools: Iterator {
1546
1572
V : Eq + Hash ,
1547
1573
F : FnMut ( & Self :: Item ) -> V ,
1548
1574
{
1549
- unique_impl:: unique_by ( self , f)
1575
+ unique_impl:: unique_by_with_hasher ( self , f, RandomState :: new ( ) )
1576
+ }
1577
+
1578
+ /// Return an iterator which yields the same elements as the one returned by
1579
+ /// [.unique_by()](crate::Itertools::unique_by), but uses the specified hash builder to hash
1580
+ /// the elements for comparison.
1581
+ ///
1582
+ /// Warning: `hash_builder` is normally randomly generated, and is designed to allow it's
1583
+ /// users to be resistant to attacks that cause many collisions and very poor performance.
1584
+ /// Setting it manually using this function can expose a DoS attack vector.
1585
+ ///
1586
+ /// ```
1587
+ /// use std::hash::RandomState;
1588
+ /// use itertools::Itertools;
1589
+ ///
1590
+ /// let data = vec!["a", "bb", "aa", "c", "ccc"];
1591
+ /// itertools::assert_equal(data.into_iter().unique_by_with_hasher(|s| s.len(), RandomState::new()),
1592
+ /// vec!["a", "bb", "ccc"]);
1593
+ /// ```
1594
+ #[ cfg( feature = "use_std" ) ]
1595
+ fn unique_by_with_hasher < V , F , S > ( self , f : F , hash_builder : S ) -> UniqueBy < Self , V , F , S >
1596
+ where
1597
+ Self : Sized ,
1598
+ V : Eq + Hash ,
1599
+ F : FnMut ( & Self :: Item ) -> V ,
1600
+ S : BuildHasher ,
1601
+ {
1602
+ unique_impl:: unique_by_with_hasher ( self , f, hash_builder)
1550
1603
}
1551
1604
1552
1605
/// Return an iterator adaptor that borrows from this iterator and
0 commit comments