#10130: Revamp __hash__, __cmp__ and __richcmp__
---------------------------+------------------------------------------------
   Reporter:  roed         |       Owner:  robertwb  
       Type:  enhancement  |      Status:  new       
   Priority:  major        |   Milestone:  sage-4.6.1
  Component:  coercion     |    Keywords:            
     Author:               |    Upstream:  N/A       
   Reviewer:               |      Merged:            
Work_issues:               |  
---------------------------+------------------------------------------------

Comment(by roed):

 I don't know the best way to resolve these issues, but here are some
 ideas.
  * Have cpdef'd functions `_hash_`, `_cmp_` and `_richcmp_` that users
 will override.
  * For parents, add an attribute "cdef public long `__hash`".  I don't
 know if this should be set to self._hash_() during the parent's `__init__`
 method, or set to -1 and then reset upon the first call to `__hash__`.
  * For `SageObject`, have the default behavior of `_hash_()` be to return
 `hash(repr(self))`.  For parents, have the default value of hash depend on
 `self.construction()`?
  * For elements, don't cache the hash by default.
  * Have the results of ==, <, etc, depend on `_richcmp_`.  By default,
 have `_richcmp_` determined by a total ordering implemented by `_cmp_`.
 So if you want to have partial ordering, or a different partial and total
 ordering, you need to implement both `_cmp_` and `_richcmp_`.
  * For parents, `_cmp_` checks first for pointer equality.  If non-equal,
 it compares the hashes.  If those are nonequal, returns the cmp of the
 hashes.  Otherwise, returns the cmp of the pointers.
  * Elements would have no default `_cmp_`, but would instead raise an
 error.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10130#comment:1>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to