hash | Returns a numeric hash of obj. |
hashIterable | Returns a numeric hash of the input iterable. |
hashString | Returns a numeric hash of the input string. |
key | Extracts a hash key from obj. |
utils.hash(obj)If obj is a number, it is simply returned.
If obj is a table with a __hash metamethod, that method is called with obj as an argument and the result is returned.
If obj is a table with no __hash metamethod, this function returns utils.hashString(tostring(obj)).
For all other cases, this function returns utils.hashString(tostring(obj)).
utils.hashIterable(iterable)This method accumulates the hash value by iterating, for each e in iter(iterable), hash = hash*prime + utils.hash(e).
If hash exceeds some large prime, it is reduced to math.mod(hash, largePrime) and accumulation continues.
The primes chosen for this function were selected arbitrarily.
utils.hashString(str)This method accumulates the hash value by iterating, for each index [1..string.len(str)], hash = hash*prime + string.byte(str, i).
If hash exceeds some large prime, it is reduced to math.mod(hash, largePrime) and accumulation continues.
utils.key(obj)If obj is not a table, it is simply returned. If obj is a table whose metatable, mt, has a __hash metamethod, mt.__hash(obj) is returned.
This is method is used to generate hash keys for HashMap and HashSet.