mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-03-07 21:27:55 -05:00
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.
This commit is contained in:
parent
bb6de2ff05
commit
d493f6696b
3 changed files with 8 additions and 3 deletions
|
|
@ -7,7 +7,7 @@ type 'a t = 'a -> hash
|
||||||
type 'a iter = ('a -> unit) -> unit
|
type 'a iter = ('a -> unit) -> unit
|
||||||
type 'a gen = unit -> 'a option
|
type 'a gen = unit -> 'a option
|
||||||
|
|
||||||
(* FNV hashing
|
(* FNV-1 hashing (multiply then XOR)
|
||||||
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||||
*)
|
*)
|
||||||
let fnv_offset_basis = 0xcbf29ce484222325L
|
let fnv_offset_basis = 0xcbf29ce484222325L
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ include Int
|
||||||
|
|
||||||
type 'a iter = ('a -> unit) -> unit
|
type 'a iter = ('a -> unit) -> unit
|
||||||
|
|
||||||
(* use FNV:
|
(* use FNV-1:
|
||||||
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function *)
|
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function *)
|
||||||
external hash : (int[@untagged]) -> (int[@untagged])
|
external hash : (int[@untagged]) -> (int[@untagged])
|
||||||
= "caml_cc_hash_int_byte" "caml_cc_hash_int" [@@noalloc]
|
= "caml_cc_hash_int_byte" "caml_cc_hash_int" [@@noalloc]
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
#include <caml/mlvalues.h>
|
#include <caml/mlvalues.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* FNV-1a hash for a 64-bit integer.
|
/* FNV-1 hash for a 64-bit integer.
|
||||||
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||||
|
|
||||||
|
FNV-1 order: multiply then XOR (as opposed to FNV-1a which XORs first).
|
||||||
|
Uses the standard 64-bit FNV parameters:
|
||||||
|
offset_basis = 0xcbf29ce484222325
|
||||||
|
prime = 0x00000100000001b3
|
||||||
|
|
||||||
Core routine: operates on all 8 bytes of an int64_t. */
|
Core routine: operates on all 8 bytes of an int64_t. */
|
||||||
|
|
||||||
static inline int64_t cc_fnv_hash_int64(int64_t n) {
|
static inline int64_t cc_fnv_hash_int64(int64_t n) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue