This commit is contained in:
Simon Cruanes 2026-03-15 03:25:54 +00:00
parent abe924eb57
commit 31eb8d163f
3 changed files with 30 additions and 13 deletions

View file

@ -23,8 +23,8 @@ let rec hash t =
| List l -> H.combine2 20 (H.list hash l) | List l -> H.combine2 20 (H.list hash l)
| Map l -> | Map l ->
H.combine2 30 H.combine2 30
(H.iter (H.pair H.string hash) @@ fun k -> ( H.iter (H.pair H.string hash) @@ fun k ->
Str_map.iter (fun x y -> k (x, y)) l) Str_map.iter (fun x y -> k (x, y)) l )
let int64 i : t = Int i let int64 i : t = Int i
let int i : t = int64 (Int64.of_int i) let int i : t = int64 (Int64.of_int i)

View file

@ -7,7 +7,6 @@ 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
let[@inline] combine2 a b = let[@inline] combine2 a b =
Hash_impl_.(finalize (combine_int (combine_int seed a) b)) Hash_impl_.(finalize (combine_int (combine_int seed a) b))
@ -56,7 +55,9 @@ let bool b =
let char x = Hash_impl_.(finalize (combine_char seed (Char.code x))) let char x = Hash_impl_.(finalize (combine_char seed (Char.code x)))
let int64 (n : int64) : int = Hash_impl_.(finalize (combine_i64 seed n)) let int64 (n : int64) : int = Hash_impl_.(finalize (combine_i64 seed n))
let int32 (x : int32) : int = Hash_impl_.(finalize (combine_i32 seed x)) let int32 (x : int32) : int = Hash_impl_.(finalize (combine_i32 seed x))
let nativeint (x : nativeint) = Hash_impl_.(finalize (combine_i64 seed (Int64.of_nativeint x)))
let nativeint (x : nativeint) =
Hash_impl_.(finalize (combine_i64 seed (Int64.of_nativeint x)))
let bytes (x : bytes) = let bytes (x : bytes) =
Hash_impl_.(finalize (combine_string seed (Bytes.unsafe_to_string x))) Hash_impl_.(finalize (combine_string seed (Bytes.unsafe_to_string x)))
@ -76,8 +77,7 @@ let slice x i len =
let opt f = function let opt f = function
| None -> 42 | None -> 42
| Some x -> | Some x -> Hash_impl_.(finalize (combine_int (combine_int seed 43) (f x)))
Hash_impl_.(finalize (combine_int (combine_int seed 43) (f x)))
let list f l = let list f l =
let s = let s =
@ -87,7 +87,9 @@ let list f l =
let array f a = let array f a =
let s = let s =
Array.fold_left (fun s x -> Hash_impl_.combine_int s (f x)) Hash_impl_.seed a Array.fold_left
(fun s x -> Hash_impl_.combine_int s (f x))
Hash_impl_.seed a
in in
Hash_impl_.finalize s Hash_impl_.finalize s

View file

@ -5,18 +5,27 @@
type state = int64 type state = int64
let seed : state = Hash_impl_.seed let seed : state = Hash_impl_.seed
let[@inline] finalize64 (s : state) : int64 = Hash_impl_.fmix64 s let[@inline] finalize64 (s : state) : int64 = Hash_impl_.fmix64 s
let[@inline] finalize (s : state) : int = Hash_impl_.finalize s let[@inline] finalize (s : state) : int = Hash_impl_.finalize s
type 'a t = state -> 'a -> state type 'a t = state -> 'a -> state
let[@inline] int s x = Hash_impl_.combine_int s x let[@inline] int s x = Hash_impl_.combine_int s x
let[@inline] bool s b = Hash_impl_.combine_int s (if b then 1 else 2)
let[@inline] bool s b =
Hash_impl_.combine_int s
(if b then
1
else
2)
let[@inline] char s c = Hash_impl_.combine_char s (Char.code c) let[@inline] char s c = Hash_impl_.combine_char s (Char.code c)
let[@inline] int64 s (x : int64) = Hash_impl_.combine_i64 s x let[@inline] int64 s (x : int64) = Hash_impl_.combine_i64 s x
let[@inline] int32 s (x : int32) = Hash_impl_.combine_i32 s x let[@inline] int32 s (x : int32) = Hash_impl_.combine_i32 s x
let[@inline] nativeint s (x : nativeint) = Hash_impl_.combine_i64 s (Int64.of_nativeint x)
let[@inline] nativeint s (x : nativeint) =
Hash_impl_.combine_i64 s (Int64.of_nativeint x)
let[@inline] string s x = Hash_impl_.combine_string s x let[@inline] string s x = Hash_impl_.combine_string s x
let[@inline] bytes s x = Hash_impl_.combine_string s (Bytes.unsafe_to_string x) let[@inline] bytes s x = Hash_impl_.combine_string s (Bytes.unsafe_to_string x)
@ -26,7 +35,8 @@ let slice str ofs s len =
if k = j then if k = j then
st st
else else
loop (k + 1) (Hash_impl_.combine_char st (Char.code (String.unsafe_get str k))) loop (k + 1)
(Hash_impl_.combine_char st (Char.code (String.unsafe_get str k)))
in in
loop ofs s loop ofs s
@ -39,9 +49,14 @@ let array f s a = Array.fold_left f s a
let pair f g s (x, y) = g (f s x) y let pair f g s (x, y) = g (f s x) y
let triple f g h s (x, y, z) = h (g (f s x) y) z let triple f g h s (x, y, z) = h (g (f s x) y) z
let quad f g h k s (x, y, z, w) = k (h (g (f s x) y) z) w let quad f g h k s (x, y, z, w) = k (h (g (f s x) y) z) w
let map proj f s x = f s (proj x) let map proj f s x = f s (proj x)
let if_ b then_ else_ s x = if b then then_ s x else else_ s x
let if_ b then_ else_ s x =
if b then
then_ s x
else
else_ s x
let poly s x = Hash_impl_.combine_int s (Hashtbl.hash x) let poly s x = Hash_impl_.combine_int s (Hashtbl.hash x)
type 'a iter = ('a -> unit) -> unit type 'a iter = ('a -> unit) -> unit