What hash function does Ruby use?

前端 未结 1 1091
孤独总比滥情好
孤独总比滥情好 2021-02-13 15:40

What is Ruby\'s hash function algorithm?

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-13 16:01

    The standard Ruby implementation uses the Murmur hash for some types (integer, string)

    From string.c:1901:

    /* MurmurHash described in http://murmurhash.googlepages.com/ */
    static unsigned int
    hash(const unsigned char * data, int len, unsigned int h)
    

    (note that this function seems to be renamed to st_hash in the SVN trunk)

    Search for rb_memhash in the source code if you want to know where it gets used. I have used the Murmur2 hash in an own project before, it is very fast and has good cryptographic properties (but not good enough to be used as cryptographic hash function).

    0 讨论(0)
提交回复
热议问题