# OpenEuphoria Manual

## Euphoria v4.1

routine or constant name search

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.31 Flags | Up: 8 API Reference | 8.33 Map (Hash Table) > | 9 Release Notes >>

## 8.32 Hashing Algorithms

### 8.32.1 Type Constants

#### 8.32.1.1 HSIEH30

    include std/hash.e
    namespace stdhash
    public enum HSIEH30

#### 8.32.1.2 HSIEH32

    include std/hash.e
    namespace stdhash
    public enum HSIEH32

#### 8.32.1.3 ADLER32

    include std/hash.e
    namespace stdhash
    public enum ADLER32

#### 8.32.1.4 FLETCHER32

    include std/hash.e
    namespace stdhash
    public enum FLETCHER32

#### 8.32.1.5 MD5

    include std/hash.e
    namespace stdhash
    public enum MD5

#### 8.32.1.6 SHA256

    include std/hash.e
    namespace stdhash
    public enum SHA256

### 8.32.2 Routines

#### 8.32.2.1 hash

    <built-in> function hash(object source, atom algo)

calculates a hash value for a key using the algorithm `algo`.

##### Parameters:

1. `source` : Any Euphoria object
2. `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 one, 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

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.31 Flags | Up: 8 API Reference | 8.33 Map (Hash Table) > | 9 Release Notes >>