#14054: Cythoned UniqueRepresentation
-----------------------------------------------+----------------------------
Reporter: SimonKing | Owner: tbd
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-5.7
Component: performance | Resolution:
Keywords: cython UniqueRepresentation | Work issues:
Report Upstream: N/A | Reviewers: Travis
Scrimshaw
Authors: Simon King | Merged in:
Dependencies: #14017 | Stopgaps:
-----------------------------------------------+----------------------------
Comment (by SimonKing):
To answer the question about the hash contract:
Apparently dictionaries use the rich comparison methods and not cmp:
{{{
sage: class Bla(object):
....: def __hash__(self):
....: return 2
....: def __cmp__(self, other):
....: return 0
....: def __eq__(self, other):
....: return self is other
....: def __ne__(self, other):
....: return self is not other
....:
sage: a = Bla()
sage: b = Bla()
sage: a==b
False
sage: hash(a)==hash(b)
True
sage: cmp(a,b)
0
sage: D = {a:1}
}}}
Since `hash(a)==hash(b)`, a and b belong to the same hash bucket of the
dictionary. And comparison by cmp tells that they are equal. But we still
have:
{{{
sage: D[b]
---------------------------------------------------------------------------
KeyError Traceback (most recent call
last)
<ipython-input-8-6cf1ee6b63d5> in <module>()
----> 1 D[b]
KeyError: <__main__.Bla object at 0x5064310>
}}}
Hence, dictionaries use comparison by `==`, and thus my patch does the
right thing, IMHO.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14054#comment:13>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" 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-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.