你能否介绍一下哈希函数/算法Perl用来将字符串映射到索引?任何相关的阅读?Perl使用什么哈希函数/算法?
9
A
回答
15
PERL_HASH_INTERNAL_
,在hv.h
定义,下面复制:
/* hash a key */
/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins
* from requirements by Colin Plumb.
* (http://burtleburtle.net/bob/hash/doobs.html) */
/* The use of a temporary pointer and the casting games
* is needed to serve the dual purposes of
* (a) the hashed data being interpreted as "unsigned char" (new since 5.8,
* a "char" can be either signed or unsigned, depending on the compiler)
* (b) catering for old code that uses a "char"
*
* The "hash seed" feature was added in Perl 5.8.1 to perturb the results
* to avoid "algorithmic complexity attacks".
*
* If USE_HASH_SEED is defined, hash randomisation is done by default
* If USE_HASH_SEED_EXPLICIT is defined, hash randomisation is done
* only if the environment variable PERL_HASH_SEED is set.
* For maximal control, one can define PERL_HASH_SEED.
* (see also perl.c:perl_parse()).
*/
#define PERL_HASH_INTERNAL_(hash,str,len,internal) \
STMT_START { \
register const char * const s_PeRlHaSh_tmp = str; \
register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; \
register I32 i_PeRlHaSh = len; \
register U32 hash_PeRlHaSh = (internal ? PL_rehash_seed : PERL_HASH_SEED); \
while (i_PeRlHaSh--) { \
hash_PeRlHaSh += *s_PeRlHaSh++; \
hash_PeRlHaSh += (hash_PeRlHaSh << 10); \
hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6); \
} \
hash_PeRlHaSh += (hash_PeRlHaSh << 3); \
hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); \
(hash) = (hash_PeRlHaSh + (hash_PeRlHaSh << 15)); \
} STMT_END
相关问题
- 1. Ruby使用什么哈希函数?
- 2. Rabin-Karp算法的最佳哈希函数是什么?
- 3. javascript关联数组使用什么样的哈希函数/算法?
- 4. Perl哈希哈希
- 5. Perl中的哈希和哈希引用有什么区别?
- 6. object.hashCode使用什么哈希方法?
- 7. 哈希方法使用什么平等?
- 8. 什么是杜鹃哈希中的“新哈希函数”?
- 9. 哈希哈希在Perl中
- 10. Perl的哈希使用
- 11. Perl,使用哈希“闭包”
- 12. 有什么办法在Perl中获取哈希数组名称?
- 13. 我应该使用什么哈希算法?
- 14. Python的字典映射使用什么哈希算法?
- 15. @Password公式正在使用什么哈希算法?
- 16. 哈希函数为什么要使用素数模数?
- 17. 引用Perl哈希
- 18. 函数计算哈希数,它到底做了什么,为什么?
- 19. 在Perl中使用哈希和数组
- 20. C++哈希算法
- 21. Perl的哈希
- 22. 哈希在Perl
- 23. 为什么Perl警告我使用伪哈希?
- 24. 什么SHA2哈希函数不境界点网使用
- 25. 什么是Firefox中使用的当前缓存哈希函数?
- 26. 什么哈希算法考虑了可变长度数据
- 27. 为什么RSACryptoServiceProvider.SignHash有一个“哈希算法标识符”参数?
- 28. 为什么RSACryptoServiceProvider.VerifyHash有一个“哈希算法标识符”参数?
- 29. 在iOS上使用SHA256哈希算法
- 30. 使用Python检测SSL哈希算法
你到底想干什么?你能提供一些不起作用的代码的例子吗? –
任何会造成冲突的键:) – Jean
没有两个键总是会碰撞。散列在必要时被随机扰动。 – ikegami