In OCaml Hashtblcan hashadd any thing to int
Hashtbl
hash
Hashtbl.hash x associates a non-negative integer with any value of any type. It is guaranteed that if x = y or Pervasives.compare xy = 0, then hash x = hash y. Moreover, the hash always ends even on cyclic structures.
I mean, in Javawe have hashCode()for every object that returns an integer, and Java Hashtable can hash this integer.
Java
hashCode()
But how did OCaml achieve this to hash something?
. Hashtbl.hash , , . , , . , , , .
Hashtbl.hash
byterun/hash.c OCaml.
, , Hashtbl.hash OCaml. , OCaml ( ), . 'a -> int , . , - , .
'a -> int
Hashtbl.hash OCaml, . OCaml, . compare ( =).
compare
=