16位哈希 [英] 16bit hash
问题描述
有什么方法可以在python中获得高效的16位哈希值?
-
罗宾贝克尔
Robin Becker写道:
是否有办法在python中获得高效的16位哈希?
hash(obj)& 65535
- Josiah
< blockquote> Josiah Carlson写道:
Robin Becker写道:
>有什么方法可以获得python中有效的16位哈希?
hash(obj)& 65535
- Josiah
是的,我想到了这一点,但无法弄清楚内部哈希是否真的是
均匀分配比特。特别是因为它似乎对待整数等
作为特殊情况
>> hash(1)
1
>> hash(2)
2
>> hash('''1234'')
1723328704
>>>
-
Robin Becker
Robin Becker< ro *** @ reportlab.comwrote:
是否有办法在python中获得高效的16位哈希?
这是一个32位的crc,你可以使用最后16位作为16位
位哈希...
>> import binascii
binascii.crc32(" hello world")
222957957
>> crc = binascii.crc32(" hello")
crc = binascii.crc32(" world",crc)
crc
222957957
>>>
如果你想知道它有多快......
Is the any way to get an efficient 16bit hash in python?
--
Robin Becker
Robin Becker wrote:Is the any way to get an efficient 16bit hash in python?hash(obj)&65535
- Josiah
Josiah Carlson wrote:Robin Becker wrote:>Is the any way to get an efficient 16bit hash in python?
hash(obj)&65535
- Josiahyes I thought of that, but cannot figure out if the internal hash really
distributes the bits evenly. Particularly since it seems to treat integers etc
as special cases
>>hash(1)
1
>>hash(2)
2
>>hash(''1234'')
1723328704
>>>
--
Robin Becker
Robin Becker <ro***@reportlab.comwrote:Is the any way to get an efficient 16bit hash in python?Here is a 32 bit crc of which you could use the bottom 16 bits as a 16
bit hash...
>>import binascii
binascii.crc32("hello world")
222957957
>>crc = binascii.crc32("hello")
crc = binascii.crc32(" world", crc)
crc
222957957
>>>
And in case you are wondering how fast it is...
这篇关于16位哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!