Commit graph

2 commits

Author SHA1 Message Date
Simon Cruanes
d493f6696b Fix FNV variant in comments: this is FNV-1, not FNV-1a
The implementation uses multiply-then-XOR order, which is FNV-1.
FNV-1a would XOR first, then multiply. The constants (offset_basis
and prime) are the same for both variants; only the operation order
differs. Fix comments in cc_stubs.c, CCInt.ml, and CCHash.ml.

No behavioral change — just correcting the documentation.
2026-02-16 12:48:12 +00:00
Simon Cruanes
bb6de2ff05 CCInt.hash: replace OCaml Int64 loop with C stub (FNV-1)
Implement FNV-1 hashing for CCInt.hash as a C stub instead of a
pure-OCaml Int64-based loop. The core hash function operates on int64
with separate native/bytecode entry points for both int and int64.

- cc_stubs.c: cc_fnv_hash_int64 core, with int and int64 wrappers
- Uses [@untagged] for int args, [@unboxed] ready for int64
- OCAML_INT_MASK ensures correct byte extraction for 63-bit ints
- Hash values are unchanged from the previous OCaml implementation

Also adds a throughput benchmark in benchs/run_benchs.ml comparing
the old pure-OCaml FNV hash vs the new C stub (~2x faster).
2026-02-16 12:48:12 +00:00