diff --git a/src/core/CCHash.ml b/src/core/CCHash.ml index b4fdc384..c34b9341 100644 --- a/src/core/CCHash.ml +++ b/src/core/CCHash.ml @@ -7,7 +7,7 @@ type 'a t = 'a -> hash type 'a iter = ('a -> unit) -> unit 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 *) let fnv_offset_basis = 0xcbf29ce484222325L diff --git a/src/core/CCInt.ml b/src/core/CCInt.ml index 09d1ba85..016caf69 100644 --- a/src/core/CCInt.ml +++ b/src/core/CCInt.ml @@ -4,7 +4,7 @@ include Int 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 *) external hash : (int[@untagged]) -> (int[@untagged]) = "caml_cc_hash_int_byte" "caml_cc_hash_int" [@@noalloc] diff --git a/src/core/cc_stubs.c b/src/core/cc_stubs.c index 1c6befd9..9c4426ea 100644 --- a/src/core/cc_stubs.c +++ b/src/core/cc_stubs.c @@ -1,9 +1,14 @@ #include #include -/* 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 + 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. */ static inline int64_t cc_fnv_hash_int64(int64_t n) {