Up | TOC | Index | |||||
<< 7 Included Tools | < 8.30 Flags | Up: 8 API Reference | 8.32 Map (hash table) > | 9 Release Notes >> |
8.31 Hashing Algorithms
8.31.1 Type Constants
8.31.1.1 HSIEH30
include std/hash.e namespace stdhash public enum HSIEH30
8.31.1.2 HSIEH32
include std/hash.e namespace stdhash public enum HSIEH32
8.31.1.3 ADLER32
include std/hash.e namespace stdhash public enum ADLER32
8.31.1.4 FLETCHER32
include std/hash.e namespace stdhash public enum FLETCHER32
8.31.1.5 MD5
include std/hash.e namespace stdhash public enum MD5
8.31.1.6 SHA256
include std/hash.e namespace stdhash public enum SHA256
8.31.2 Routines
8.31.2.1 hash
<built-in> function hash(object source, atom algo)
Calculates a hash value from key using the algorithm algo
Parameters:
- source : Any Euphoria object
- algo : A code indicating which algorithm to use.
- HSIEH30 uses Hsieh. Returns a 30-bit (a Euphoria integer). Fast and good dispersion
- HSIEH32 uses Hsieh. Returns a 32-bit value. Fast and very good dispersion
- ADLER32 uses Adler. Very fast and reasonable dispersion, especially for small strings
- FLETCHER32 uses Fletcher. Very fast and good dispersion
- MD5 uses MD5 (not implemented yet) Slower but very good dispersion. Suitable for signatures.
- SHA256 uses SHA256 (not implemented yet) Slow but excellent dispersion. Suitable for signatures. More secure than MD5.
- 0 and above (integers and decimals) and non-integers less than zero use the cyclic variant (hash = hash * algo + c). This is a fast and good to excellent dispersion depending on the value of algo. Decimals give better dispersion but are slightly slower.
Returns:
An atom, Except for the HSIEH30, MD5 and SHA256 algorithms, this is a 32-bit integer.
An integer, Except for the HSIEH30 algorithms, this is a 30-bit integer.
A sequence, MD5 returns a 4-element sequence of integers
SHA256 returns a 8-element sequence of integers.
Comments:
- For algo values from zero to less than 1, that actual value used is (algo + 69096).
Example 1:
? hash("The quick brown fox jumps over the lazy dog", 0 ) --> 3071488335 ? hash("The quick brown fox jumps over the lazy dog", 99 ) --> 4122557553 ? hash("The quick brown fox jumps over the lazy dog", 99.94 ) --> 95918096 ? hash("The quick brown fox jumps over the lazy dog", -99.94 ) --> 4175585990 ? hash("The quick brown fox jumps over the lazy dog", HSIEH30 ) --> 96435427 ? hash("The quick brown fox jumps over the lazy dog", HSIEH32 ) --> 96435427 ? hash("The quick brown fox jumps over the lazy dog", ADLER32 ) --> 1541148634 ? hash("The quick brown fox jumps over the lazy dog", FLETCHER32) --> 1730140417 ? hash(123, 99 ) --> 1188623852 ? hash(1.23, 99 ) --> 3808916725 ? hash({1, {2,3, {4,5,6}, 7}, 8.9}, 99 ) --> 526266621