The IDL_HASHVAR function returns a hash code value for a given variable.
The hash code value is computed using Bob Jenkins' One-At-A-Time hash and produces a 32-bit hash code. Given an input key of length n bytes, the algorithm is:
for (i = 0
hash += key[i]
hash += (hash << 10)
hash ^= (hash >> 6)
}
hash += (hash << 3)
hash ^= (hash >> 11)
hash += (hash << 15)
Note: The IDL_HASHVAR function is designed for creating simple hash code values, and is useful for converting arbitrary values into 32-bit (four byte) hash codes with a uniform distribution. It can also be used to determine if two strings are identical, as a slight difference in the strings (say a single character) will product completely different hashes. It is not designed for cryptographic purposes, and should not be used for that purpose. For encrypting or decrypting strings, see IDL_String::Decrypt/Encrypt.
Brief Example
IDL> print, idl_hashvar('Keanu Reeves'), idl_hashvar('Keanu Jeeves')
3160331264 3683530696
IDL> print, idl_hashvar(123b), idl_hashvar(123.0), idl_hashvar(123uLL)
3044569485 3044569485 3044569485
Syntax
Result = IDL_HASHVAR( Key )
Return Value
Returns an unsigned 32-bit integer giving the hash code for Key.
Arguments
Key
The scalar or array to be hashed. Object references and pointers are hashed according to their heap reference ID. All IDL numeric types are converted to type double before computing the hash value. For strings, the hash is computed by walking through the string character-by-character and combining all of them into a single hash value. For numeric arrays, the hash is computed by converting each element to a double and combining all of them into a single hash value. Complex values are hashed by combining the hashes of the real and imaginary parts.
Keywords
None
Version History
See Also
HASH, IDL_String::Decrypt/Encrypt