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

Hashes are assumed to be only usize #60

Closed
cuviper opened this issue Apr 12, 2019 · 6 comments · Fixed by #62
Closed

Hashes are assumed to be only usize #60

cuviper opened this issue Apr 12, 2019 · 6 comments · Fixed by #62

Comments

@cuviper
Copy link
Member

cuviper commented Apr 12, 2019

h1 will fail on 32-bit targets if a hasher yields a u64 greater than u32::MAX:
https://github.com/Amanieu/hashbrown/blob/9068eb7a2268d879dc4453ac72238e8a992f1469/src/raw/mod.rs#L120-L126

The comment in h2 gives some insight to this, but that only applies to FxHash:
https://github.com/Amanieu/hashbrown/blob/9068eb7a2268d879dc4453ac72238e8a992f1469/src/raw/mod.rs#L131-L138

See also the failure in rust-lang/rust#58623 (comment)

@Amanieu
Copy link
Member

Amanieu commented Apr 12, 2019

Yes, this assert was mistakenly added as part of the clippy support, it should be removed.

@cuviper
Copy link
Member Author

cuviper commented Apr 12, 2019

Are there any tests using alternate hashes? Even RandomState should trigger this.

@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 12, 2019

Replacing the assert with a comment explaining why the truncation is ok and adding a test that triggers this sounds good to me.

bors bot added a commit that referenced this issue Apr 12, 2019
61: Improve worst-case performance of HashSet.is_subset r=Amanieu a=Amanieu

Ported from rust-lang/rust#59665

62: Remove incorrect debug_assert r=Amanieu a=Amanieu

Fixes #60 

Co-authored-by: Amanieu d'Antras <[email protected]>
bors bot added a commit that referenced this issue Apr 12, 2019
62: Remove incorrect debug_assert r=Amanieu a=Amanieu

Fixes #60 

Co-authored-by: Amanieu d'Antras <[email protected]>
bors bot added a commit that referenced this issue Apr 13, 2019
62: Remove incorrect debug_assert r=Amanieu a=Amanieu

Fixes #60 

Co-authored-by: Amanieu d'Antras <[email protected]>
bors bot added a commit that referenced this issue Apr 13, 2019
56: Add additional benchmarks. r=Amanieu a=tkaitchuck

This covers performance of three cases I wanted to study when looking into https://github.com/Amanieu/hashbrown/issues/48

They are:
`grow_by_insertion_kb` which is similar to grow by insertion, but instead of every entry differing by 1, they differ by 1024. This makes an important performance difference to the hasher.

`find_existing_high_bits` which is similar to find_existing but uses 64 bit keys instead of 32 bit keys, where the lower 32 bits are zeros. This is a pathologically bad case for FxHash.

`insert_8_char_string` tests a case where the key is a string. (As opposed to all the existing tests which operate on u32 values. This is important to cover because strings as keys are very common.

62: Remove incorrect debug_assert r=Amanieu a=Amanieu

Fixes #60 

Co-authored-by: Tom Kaitchuck <[email protected]>
Co-authored-by: Amanieu d'Antras <[email protected]>
@bors bors bot closed this as completed in #62 Apr 13, 2019
bors bot added a commit that referenced this issue Apr 14, 2019
63: Add sanity checks with alternate hashers r=Amanieu a=cuviper

The `max` and `random_state` tests currently fail on 32-bit targets per #60.

Co-authored-by: Josh Stone <[email protected]>
@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 14, 2019

Is there an issue open to add a test for this ? The merged PR does not add any.

Or was that added in https://github.com/Amanieu/hashbrown/pull/63 ?

@Amanieu
Copy link
Member

Amanieu commented Apr 14, 2019

Tests were added in #63.

@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 14, 2019

Awesome, thank you both for fixing this, and sorry that I broke it!

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 a pull request may close this issue.

3 participants