Hash function (djb2)

/// @brief Implementation of djb2 in plain Igor Pro
///
/// The implementation here does support embedded nulls, see DisplayHelpTopic "Embedded Nulls in Literal Strings".
///
/// See also https://github.com/dim13/djb2/blob/master/docs/hash.md#djb2.
threadsafe Function [uint64 h] HM_DJBHash(string str)

    uint64 d
    h = 5381
    WAVE/U/B wv = StringToUnsignedByteWave(str)

    for(d : wv)
        h = h * 33 + d
    endfor

    return [h]
End

This is also a nice example for when and how to use the integer types. 

Forum

Support

Gallery

Igor Pro 10

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More