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.

hashCombine

(hash1 hash2 -- hash) Combines two Nat32 hashes into one Nat32 hash that depends on their order.

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