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

fix(murmurHash): fix murmurHash3 implementation, add tests #83

Merged
merged 6 commits into from
Sep 15, 2024

Conversation

Hexagon
Copy link
Contributor

@Hexagon Hexagon commented Sep 14, 2024

Changes:

  • Fixes the murmurHash implementation by falling through all remainders as intended, instead of breaking.
  • Removes an outdated JSDoc comment stating ASCII only for the data parameter, while it does in fact encode JavaScript strings using UTF-8 through TextEncoder().encode(), which matches how most other implementations do it.
  • Updates the hash value produced by murmurHash in the README example.
  • To prevent regression bugs, some basic test cases are added, covering seeds, UTF-8, Uint8Arrays, different input lengths, and the maximum safe seed value.
  • Ensures compatibility with other implementations through testing known inputs, seeds, and outputs.

Please note:

About 50% of the hashes produced by murmurHash prior to this fix are incorrect, so handle with care.

Additional notes:

Resolves #82 and #11

@Hexagon Hexagon changed the title fix(murmurHash): Fix murmurHash implementation, add tests fix(murmurHash): Fix murmurHash3 implementation, add tests Sep 14, 2024
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Nice find. Thanks for the fix and tests ❤️

@pi0 pi0 changed the title fix(murmurHash): Fix murmurHash3 implementation, add tests fix(murmurHash): fix murmurHash3 implementation, add tests Sep 15, 2024
@pi0 pi0 merged commit 3e211ad into unjs:main Sep 15, 2024
2 checks passed
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.

murmurHash is severely broken, producing identical hashes for different inputs
2 participants