Ruby使用什么散列函数? [英] What hash function does Ruby use?

查看:89
本文介绍了Ruby使用什么散列函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Ruby的散列函数算法? 标准Ruby实现使用 Murmur hash
$ b

从string.c:1901: / p>

  / * MurmurHash在http://murmurhash.googlepages.com/ * / 
中描述static unsigned int $ b $ (注意,这个函数是一个函数,它是一个函数,它是一个数组,似乎在SVN中继中重命名为 st_hash



搜索 rb_memhash <源代码中的code>如果你想知道它在哪里被使用。我之前在自己的项目中使用过Murmur2哈希,它非常快速并且具有很好的加密属性(但不足以用作加密哈希函数)。


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).

这篇关于Ruby使用什么散列函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆