Skip to content

Fixed the 64-bit hash function and added unit test - #129

Merged
erincatto merged 3 commits into
mainfrom
fix_hash
Aug 13, 2026
Merged

Fixed the 64-bit hash function and added unit test#129
erincatto merged 3 commits into
mainfrom
fix_hash

Conversation

@erincatto

@erincatto erincatto commented Aug 12, 2026

Copy link
Copy Markdown
Owner

The 64-bit hash function was not well tested and had a bad optimization.
Switched to using rapidhash: https://github.com/Nicoshev/rapidhash

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Box3D’s 64-bit content hashing to avoid a mixing weakness (low hash bits not being influenced by high input bytes) and adds a targeted regression test to ensure full-width mixing for geometry content hashes.

Changes:

  • Reworked b3Hash64NonZero to hash byte-by-byte (FNV-1a) followed by a splitmix64 finalizer.
  • Added a unit test that detects the specific “upper-byte doesn’t affect low hash bits” failure mode.
  • Updated documentation/versioning references to reflect 64-bit hashing and the new hash behavior for serialized geometry.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/test_recording.c Adds GeometryHashWidth subtest to ensure the hash function reaches the full 64-bit space for structured inputs.
src/core.c Replaces the previous 8-byte-at-a-time hashing optimization with byte-wise FNV-1a and a splitmix64 finalizer.
samples/gfx/geometry_registry.h Updates comment to reflect that the geometry registry is keyed by a uint64_t content hash.
include/box3d/types.h Updates serialized-data version constants for hull/mesh/height-field to match the new hashing behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/core.c Outdated

// Fowler/Noll/Vo FNV-1a salted by length, then the splitmix64 finalizer so tiny inputs
// still spread across all bits.
// FNV-1a with splitmix64 finalizer so tiny inputs still spread across all bits.
@erincatto
erincatto merged commit 30c67b5 into main Aug 13, 2026
20 checks passed
@erincatto
erincatto deleted the fix_hash branch August 13, 2026 00:13
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