短字符串(标签名称)的最佳 32 位哈希函数是什么? [英] What is the best 32bit hash function for short strings (tag names)?
本文介绍了短字符串(标签名称)的最佳 32 位哈希函数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于相对较短的字符串,最好的 32 位哈希函数是什么?
What is the best 32bit hash function for relatively short strings?
字符串是由英文字母、数字、空格和一些附加字符(#
、$
、.
、...)例如:单元测试
、C#2.0
.
Strings are tag names that consist of English letters, numbers, spaces and some additional characters (#
, $
, .
, ...). For example: Unit testing
, C# 2.0
.
我正在寻找最佳"和最小碰撞",性能对我的目标并不重要.
I am looking for 'best' as in 'minimal collisions', performance is not important for my goals.
推荐答案
如果性能不重要,只需采用安全散列(例如 MD5 或 SHA1),并将其输出截断为 32 位.这将为您提供与随机无法区分的哈希码分布.
If performance isn't important, simply take a secure hash such as MD5 or SHA1, and truncate its output to 32 bits. This will give you a distribution of hash codes that's indistinguishable from random.
这篇关于短字符串(标签名称)的最佳 32 位哈希函数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文