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

Implement Hash for f32 and f64 only. #168

Merged
merged 1 commit into from
Feb 17, 2025
Merged

Implement Hash for f32 and f64 only. #168

merged 1 commit into from
Feb 17, 2025

Conversation

mbrubeck
Copy link
Collaborator

The previous generic implementation was slow, and potentially incorrect for custom types. Fixes #142.

The previous generic implementation was slow, and potentially incorrect
for custom types.  Fixes #142.
@mbrubeck mbrubeck merged commit 8dcc1dc into master Feb 17, 2025
4 checks passed
Comment on lines +2039 to +2048
impl<T: PrimitiveFloat> Hash for OrderedFloat<T> {
fn hash<H: Hasher>(&self, hasher: &mut H) {
let bits = if self.0.is_nan() {
T::CANONICAL_NAN_BITS
} else {
self.0.canonical_bits()
};
bits.hash(hasher);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks the original hash result because it doesn't call raw_double_bits anymore.

Our use case depends on stable hash results. @mbrubeck would you give some background why change the result? (I can understand we implement only for f32/f64)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry about that. The main reason for that change was performance. (See #142 for details.)

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.

Invalid Hash implementation
2 participants