Skip to content

Commit b8cb516

Browse files
committed
more efficient hash function
1 parent c8b85b1 commit b8cb516

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

jscomp/stubs/bs_hash_stubs.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ external hash_string : string -> int = "caml_bs_hash_string" "noalloc";;
22

33
external hash_string_int : string -> int -> int = "caml_bs_hash_string_and_int" "noalloc";;
44

5+
external hash_string_small_int : string -> int -> int = "caml_bs_hash_string_and_small_int" "noalloc";;
6+
57
external hash_int : int -> int = "caml_bs_hash_int" "noalloc";;

jscomp/stubs/ext_basic_hash_stubs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ CAMLprim value caml_bs_hash_string_and_int (value obj, value d){
4040
return Val_int(h & 0x3FFFFFFFU);
4141
}
4242

43+
CAMLprim value caml_bs_hash_string_and_small_int(value obj, value d){
44+
uint32 h = 0;
45+
h = caml_hash_mix_string(h,obj);
46+
MIX(h,d);
47+
FINAL_MIX(h);
48+
return Val_int(h & 0x3FFFFFFFU);
49+
}
50+
4351

4452
/* local variables: */
4553
/* compile-command: "ocamlopt.opt -c hash_runtime.c" */

0 commit comments

Comments
 (0)