[ZODB-Dev] Re: CVS: Products/Ape/lib/apelib/zodb3 - storage.py:1.18

Christian Zagrodnick cz at gocept.com
Fri Oct 20 03:17:17 EDT 2006


Hi,

I just want to call attention to that change. If anybody sees a problem 
with this drop me a note.

What happens is that every hash is "compressed" to a 32bit unsigned 
integer. I'm not sure why the hash function uses the hex representation 
instead of using pack, but I didn't want to change that.


On 2006-10-18 15:01:38 +0200, Christian Zagrodnick <cz at gocept.com> said:

> Update of /cvs-repository/Products/Ape/lib/apelib/zodb3
> In directory cvs.zope.org:/tmp/cvs-serv6816
> 
> Modified Files:
> 	storage.py Log Message:
> fixed the hash64 function for 64 bit machines
> 
> the hash64 maps all hash result into an unsigned 32-bit integer which 
> did break on 64bit machines because the python hash has doubled in size.
> 
> 
> === Products/Ape/lib/apelib/zodb3/storage.py 1.17 => 1.18 ===
> --- Products/Ape/lib/apelib/zodb3/storage.py:1.17	Wed Jan 12 01:53:42 2005
> +++ Products/Ape/lib/apelib/zodb3/storage.py	Wed Oct 18 09:01:36 2006
> @@ -87,10 +87,16 @@
>      def hash64(self, value):
>          """Returns an 8-byte hash value.
>          """
> -        v = hash(value)
> -        if v < 0:
> +        if v < -2L ** 32:
> +            v += 2L ** 64
> +        elif v < 0:
>              # Treat the hash as an unsigned 32-bit integer
>              v += 2L ** 32
> +        if v > 2L ** 32:
> +            v = v / 2 ** 32
> +
> +        assert v >= 0 and v <= 2L ** 32
> +
>          h = '%08x' % v
>          if h == HASH0:
>              # Avoid the special zero hash.
> 
> _______________________________________________
> Zope-CVS maillist  -  Zope-CVS at zope.org
> http://mail.zope.org/mailman/listinfo/zope-cvs
> 
> Zope CVS instructions: http://dev.zope.org/CVS

-- 
Christian Zagrodnick

gocept gmbh & co. kg  ·  forsterstrasse 29 · 06112 halle/saale
www.gocept.com · fon. +49 345 12298894 · fax. +49 345 12298891





More information about the ZODB-Dev mailing list