rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.76k stars 309 forks source link

Provide `with_hasher` alternative adaptors #998

Open jswrenn opened 4 days ago

jswrenn commented 4 days ago

All adaptors bounded by Hash would potentially benefit from a with_hasher variant that allowed supplying a faster Hasher (e.g., ahash or fxhash):

Implementing each of these is a three step process:

  1. Add trailingS = RandomState generic parameter to the adaptor type, where S: BuildHasher
  2. Replace relevant calls to HashMap::new and HashMap::default with HashMap::with_hasher
  3. Modify the adaptor type's internal constructor to consume an extra hash_builder: S parameter.
  4. Add a with_hasher adaptor to Itertools with a hash_builder: S parameter that's passed to the internal constructor.
    • The documentation for this should defer to the non-with_hasher variant.
    • The documentation should include the same warning as HashMap::with_hasher
  5. Redefine the non-with_hasher Itertools method to defer to the with_hasher variant.