Skip to content

Make CallHasher specific to ahash::RandomState#261

Merged
tkaitchuck merged 3 commits intotkaitchuck:masterfrom
dtolnay-contrib:callhasher
May 4, 2025
Merged

Make CallHasher specific to ahash::RandomState#261
tkaitchuck merged 3 commits intotkaitchuck:masterfrom
dtolnay-contrib:callhasher

Conversation

@dtolnay
Copy link
Contributor

@dtolnay dtolnay commented Apr 25, 2025

As pointed out in #242 (comment), the CallHasher trait used by the specialization feature does not need to work for arbitrary B: BuildHasher.

aHash/src/specialize.rs

Lines 20 to 22 in 3a54154

pub(crate) trait CallHasher {
fn get_hash<H: Hash + ?Sized, B: BuildHasher>(value: &H, build_hasher: &B) -> u64;
}

It's enough to work for ahash::random_state::RandomState only. This trait is private to this crate and is only ever used with ahash's RandomState.

aHash/src/specialize.rs

Lines 19 to 21 in 6dfeeae

pub(crate) trait CallHasher {
fn get_hash<H: Hash + ?Sized>(value: &H, random_state: &RandomState) -> u64;
}

This simplifies the existing nightly-only specialization and also the stable version in #242 by eliminating some unreachable branches.

@tkaitchuck tkaitchuck self-requested a review April 25, 2025 05:17
@tkaitchuck tkaitchuck merged commit a5ada48 into tkaitchuck:master May 4, 2025
8 of 9 checks passed
@dtolnay dtolnay deleted the callhasher branch May 4, 2025 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants