Namespace Pot.Crypt
Defined in: <potlite.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
Crypt and Hash utilities.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
Pot.Crypt.hashCode(data)
String hash function similar to java.lang.String.hashCode().
|
Method Detail
<static>
{Function}
Pot.Crypt.hashCode(data)
String hash function similar to java.lang.String.hashCode().
The hash code for a string is computed as
s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
where s[i] is the ith character of the string and n is the length of
the string.
We mod the result to make it between 0 (inclusive) and 2^32 (exclusive).
Pot.debug( Pot.hashCode('abc') ); // 96354 Pot.debug( Pot.hashCode([0x61, 0x62, 0x63]) ); // 96354
- Parameters:
- {String|Array|*} data
- A target data.
- Returns:
- {Number} Hash value for `string`, between 0 (inclusive) and 2^32 (exclusive). The empty string returns 0.