hash
uint64_t hash(var self);
Get the hash value for the object self.
hash_data
uint64_t hash_data(void* data, size_t num);
Hash num bytes pointed to by data using Murmurhash.
Usage
println("%li", $I(hash($I( 1)))); /* 1 */
println("%li", $I(hash($I(123)))); /* 123 */
/* 866003103 */
println("%li", $I(hash_data($I(123), size(Int))));
println("%li", $I(hash($S("Hello")))); /* -1838682532 */
println("%li", $I(hash($S("There")))); /* 961387266 */
println("%li", $I(hash($S("People")))); /* 697467069 */
Hashable
The Hash class provides a mechanism for hashing an object. This hash value should remain the same across objects that are also considered equal by the Cmp class. For objects that are not considered equal this value should aim to be evenly distributed across integers.
This is not a cryptographic hash. It is used for various objects or data structures that require fast hashing such as the Table type. Due to this it should not be used for cryptography or security.
By default an object is hashed by using its raw memory with the Murmurhash algorithm. Due to the link between them it is recommended to only override Hash and Cmp in conjunction.
struct Hash {
uint64_t (*hash)(var);
};