1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950moduleT=structtypet=intletcompare(a:int)b:Ordering.t=ifa<bthenLtelseifa=bthenEqelseGtletto_dynx=Dyn.IntxendincludeTincludeComparable.Make(T)letequal(a:t)b=a=b(* This implementation (including the comment) is taken from the Base
library. *)(* This hash was chosen from here: https://gist.github.com/badboy/6267743
It attempts to fulfill the primary goals of a non-cryptographic hash function:
- a bit change in the input should change ~1/2 of the output bits
- the output should be uniformly distributed across the output range
- inputs that are close to each other shouldn't lead to outputs that are close to
each other.
- all bits of the input are used in generating the output
In our case we also want it to be fast, non-allocating, and inlinable. *)let[@inlinealways]hash(t:t)=lett=lnott+(tlsl21)inlett=tlxor(tlsr24)inlett=t+(tlsl3)+(tlsl8)inlett=tlxor(tlsr14)inlett=t+(tlsl2)+(tlsl4)inlett=tlxor(tlsr28)int+(tlsl31);;letof_string_exns=matchint_of_stringswith|exceptionFailure_->failwith(Printf.sprintf"of_string_exn: invalid int %S"s)|s->s;;letto_stringi=string_of_intimoduleInfix=Comparator.Operators(T)letof_strings=int_of_string_optsletshift_left=Stdlib.Int.shift_leftletshift_right=Stdlib.Int.shift_rightletmax_int=Stdlib.Int.max_int