Object hashing helpers for HashTable keys.
hash
(object -- hash) Returns the hash of a number, a Cond, a Struct whose fields are all unnamed, or an object with a getHash field.- A number is cast to
Nat32and multiplied by0x9E3779B9n32with wrapping arithmetic; a Real must fitNat32after truncation. TRUEgives0x9B9773E9n32andFALSEgives0x9E3779B9n32.- A Struct whose fields are all unnamed gives the hashes of its solid items, combined left to right with
hashCombine; one such item gives its own hash, and none gives0n32. - An object with a
getHashfield gives the result of the member access.getHashwithout conversion.
hashCombine
(hash1 hash2 -- hash) Combines two Nat32 hashes into one Nat32 hash that depends on their order.- The result is
hash2 0x9E3779B9n32 * hash1 6n8 lshift + hash1 2n8 rshift + hash1 xor, with wrapping arithmetic.
Examples
Example: number, List, and getHash method
hash multiplies the number 1, combines the hashes of the items of the List (3 4), and calls the getHash method of point, which likewise combines the hashes of x and y.
"String" use
"control" use
"hash" use
Point: [{
x: 0;
y: 0;
getHash: [x hash y hash hashCombine];
}];
{} Int32 {} [
point: Point;
3 @point.!x
4 @point.!y
("number=" 1 hash LF
"list=" (3 4) hash LF
"getHash=" point hash LF) printList
0
] "main" exportFunction
Expected Output
number=2654435769
list=3071863269
getHash=3071863269
See also
- HashTable: Hash-based map module.
- murmurHash: Murmur3 32-bit hashing helpers over raw byte storage.