| 1 | let description = "siphash" |
| 2 | |
| 3 | type state |
| 4 | type hash_value = int |
| 5 | type seed = string |
| 6 | |
| 7 | external alloc : unit -> state = "siphash_alloc" |
| 8 | external reset_to : state -> seed -> state = "siphash_reset" [@@noalloc] |
| 9 | external fold_int64 : state -> int64 -> state = "siphash_fold_int64" [@@noalloc] |
| 10 | external fold_int : state -> int -> state = "siphash_fold_int" [@@noalloc] |
| 11 | external fold_float : state -> float -> state = "siphash_fold_float" [@@noalloc] |
| 12 | external fold_string : state -> string -> state = "siphash_fold_string" [@@noalloc] |
| 13 | external get_hash_value : state -> hash_value = "siphash_get_hash_value" [@@noalloc] |
| 14 | |
| 15 | let default_seed = "the_default_seed" |
| 16 | let reset ?(seed = default_seed) t = reset_to t seed |
| 17 | |
| 18 | module For_tests = struct |
| 19 | external blit_state_to_bytes : state -> bytes -> unit = "siphash_blit_hash_to_bytes" |
| 20 | [@@noalloc] |
| 21 | |
| 22 | let state_to_string state = |
| 23 | let bytes = Bytes.create (8 * 4) in |
| 24 | blit_state_to_bytes state bytes; |
| 25 | Bytes.to_string bytes |
| 26 | ;; |
| 27 | |
| 28 | let compare_state a b = compare (state_to_string a) (state_to_string b) |
| 29 | end |