Skip to content

Conversation

@vadorovsky
Copy link

Currently, GroupingMap can create a HashMap with the default RandomState.

For some kind of keys, using different BuildHasher implementation can result in better performance. Add a possibility to create a GroupingMap with a custom hasher builder, which then produces a HashMap with it.

Currently, `GroupingMap` can create a `HashMap` with the default
`RandomState`.

For some kind of keys, using different `BuildHasher` implementation can
result in better performance. Add a possibility to create a
`GroupingMap` with a custom hasher builder, which then produces a
`HashMap` with it.
@phimuemue
Copy link
Member

See also #901 and #906

@phimuemue phimuemue added the generic-container Generic vector/hasher/map label Sep 26, 2025
@phimuemue
Copy link
Member

Thanks for this.

Closing this for now, because - if we do this - we won't restrict ourselves to custom BuildHashers, but have entirely different containers.

@phimuemue phimuemue closed this Sep 26, 2025
@jswrenn
Copy link
Member

jswrenn commented Sep 26, 2025

We've been blocked for ages on the problem of abstracting over container type. Abstracting over hasher is a much simpler problem and, with type defaults, perhaps even a non-breaking change. I think we should consider this PR.

@phimuemue
Copy link
Member

Re-opening as per @jswrenn's comment.

@phimuemue phimuemue reopened this Dec 2, 2025
Copy link
Member

@phimuemue phimuemue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this looks all reasonable to me.

The only nit I have is that I'd ideally like to have less builder functions. Maybe all ::new-functions could call the respective ::with_hasher-functions, and we could get rid of grouping_map::new?

@jswrenn I'm no expert in the not-a-breaking-change business. I guess this one could be ok, because we "only" add a S: BuildHasher here and there, but existing callers may be unaffected. Could you offer a second look at this, and if you, too, say, this is fine, I'd merge it.

{
GroupingMap { iter }
let hash_builder = RandomState::new();
GroupingMap { iter, hash_builder }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a nit, but please forward this to with_hasher(iter, RandomState::new()).

@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

❌ Patch coverage is 46.15385% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.35%. Comparing base (6814180) to head (9dc78fd).
⚠️ Report is 169 commits behind head on master.

Files with missing lines Patch % Lines
src/lib.rs 8.69% 21 Missing ⚠️
src/grouping_map.rs 75.86% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1057      +/-   ##
==========================================
- Coverage   94.38%   93.35%   -1.03%     
==========================================
  Files          48       50       +2     
  Lines        6665     6355     -310     
==========================================
- Hits         6291     5933     -358     
- Misses        374      422      +48     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

generic-container Generic vector/hasher/map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants