@@ -1419,7 +1419,7 @@ pub trait Itertools: Iterator {
14191419 /// Setting it manually using this function can expose a DoS attack vector.
14201420 ///
14211421 /// ```
1422- /// use ahash ::RandomState;
1422+ /// use std::hash ::RandomState;
14231423 /// use itertools::Itertools;
14241424 ///
14251425 /// let data = vec![10, 20, 30, 20, 40, 10, 50];
@@ -1464,15 +1464,15 @@ pub trait Itertools: Iterator {
14641464 }
14651465
14661466 /// 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.
14691469 ///
14701470 /// Warning: `hash_builder` is normally randomly generated, and is designed to allow it's
14711471 /// users to be resistant to attacks that cause many collisions and very poor performance.
14721472 /// Setting it manually using this function can expose a DoS attack vector.
14731473 ///
14741474 /// ```
1475- /// use ahash ::RandomState;
1475+ /// use std::hash ::RandomState;
14761476 /// use itertools::Itertools;
14771477 ///
14781478 /// let data = vec!["a", "bb", "aa", "c", "ccc"];
@@ -1518,7 +1518,33 @@ pub trait Itertools: Iterator {
15181518 Self : Sized ,
15191519 Self :: Item : Clone + Eq + Hash ,
15201520 {
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)
15221548 }
15231549
15241550 /// Return an iterator adaptor that filters out elements that have
@@ -1546,7 +1572,34 @@ pub trait Itertools: Iterator {
15461572 V : Eq + Hash ,
15471573 F : FnMut ( & Self :: Item ) -> V ,
15481574 {
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)
15501603 }
15511604
15521605 /// Return an iterator adaptor that borrows from this iterator and
0 commit comments