Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: make Counter generic over the hashing algorithm #32

Open
HastD opened this issue Jan 15, 2023 · 2 comments
Open

Suggestion: make Counter generic over the hashing algorithm #32

HastD opened this issue Jan 15, 2023 · 2 comments

Comments

@HastD
Copy link

HastD commented Jan 15, 2023

It would be useful for Counter to be generic over the hashing algorithm, in the same way that HashMap allows alternate hashing algorithms to be specified. Currently the performance of Counter is limited by the fact that it can only use the default hashing algorithm, which is significantly slower than available alternatives in many common use-cases (albeit resistant to DoS attacks, but that's not a concern in some applications).

@coriolinus
Copy link
Owner

Feel free to make a PR. This feature is not important enough to me personally that I am likely to get to it in finite time, but I'm always happy to review code. The major concern for me is ensuring that the user experience is not adversely affected, so the new generic parameter must have a default, etc.

@chris-ha458
Copy link
Contributor

chris-ha458 commented Aug 29, 2023

I thought I could get just add

pub fn new_with_hasher<S>(hash_builder: S) -> Self 
    where 
        S: BuildHasher,
    {
        Self {
            map: HashMap::with_hasher(hash_builder),
            zero: N::zero(),
        }
    }

But it seems I would need to change all of the signatures to take the hasher S as well.

this might take a bit more time and I'll give it another go after some refactoring #36 has been done.

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

No branches or pull requests

3 participants