types.String.hash
Method on every
stringReturns str's hash.
let squadTag = "alpha-squad"
println("squadTag.hash() == \"alpha-squad\".hash() =", squadTag.hash() == "alpha-squad".hash())Output:
squadTag.hash() == "alpha-squad".hash() = trueReturn value
A non-negative int: the FNV-1a hash the VM computed once, when str was created, and cached on the string object. Equal strings always give the same hash.
Notes
Takes no arguments; the VM reports the true arity here.
This is not the same value as math.hash(str). math.hash runs its own mixing pass, seeded independently, that folds in str's cached hash together with the string's type tag and its length - so the two functions agree on which strings are equal (equal strings give equal results from either one) but not on what the number is: "x".hash() != hash("x") in general.
Example
let math = require("math")
// this method and math.hash() do not agree on the number itself.
println("\"abc\".hash() == math.hash(\"abc\") =", "abc".hash() == math.hash("abc"))Output:
"abc".hash() == math.hash("abc") = falseSee also
hash | Returns a hash value for the given object |
len | Returns the length of str in bytes. |
| string | class index |