开发者

What hash function does Ruby use?

开发者 https://www.devze.com 2023-01-08 05:07 出处:网络
开发者_如何学编程What is Ruby\'s hash function algorithm?The standard Ruby implementation uses the Murmur hash for some types (integer, string)
开发者_如何学编程

What is Ruby's hash function algorithm?


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

精彩评论

暂无评论...
验证码 换一张
取 消