On May 14, 3:42 am, Jernej Azarija <[email protected]> wrote:
> This is what the guys on #python (IRC) told me to consider
>
> >>> d1 = {-1: 0, -2: 0}>>> d2 = {-2: 0, -1: 0}>>> d1{-2: 0, -1: 0}>>> d2{-1: 
> >>> 0, -2: 0}>>> d1 == d2True>>> d1.keys()[-2, -1]>>> d2.keys()[-1, -2]>>>

That is an extremely sneaky example, and a useful one to keep in mind.
It's an instantly available hash collision:

sage: hash(int(-1))
-2
sage: hash(int(-2))
-2

Incidentally, even if all keys hash differently it can still happen
two keys fall in the same bin. Furthermore, based on the history of
the dictionaries, the number of bins stored for a given number of
entries may vary, leading to wildly varying layouts and hence key
storage orders.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to