16bit hash

Thomas Heller theller at ctypes.org
Wed Jun 27 14:03:21 EDT 2007


Robin Becker schrieb:
> Josiah Carlson wrote:
>> Robin Becker wrote:
>>> Is the any way to get an efficient 16bit hash in python?
>> 
>> hash(obj)&65535
>> 
>>   - Josiah
> yes 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
>  >>>

I'm not sure if it helps in your case, but this is pretty nifty:

http://www.amk.ca/python/code/perfect-hash

Thomas




More information about the Python-list mailing list