Ticket #10130: 10130_basic.patch

File 10130_basic.patch, 2.5 KB (added by David Roe, 12 years ago)

A few hash changes. WARNING: changes parent.pxd, so rebuilding will be slow.

  • sage/rings/finite_rings/integer_mod_ring.py

    # HG changeset patch
    # User David Roe <roed@math.harvard.edu>
    # Date 1287128320 14400
    # Node ID 24ddfa7037754001b3b254289366846972d27947
    # Parent  7555f009b44d70ff724188a7b5a5f9a115d0dccc
    [mq]: 10130_basic.patch
    
    diff -r 7555f009b44d -r 24ddfa703775 sage/rings/finite_rings/integer_mod_ring.py
    a b  
    724724   
    725725    def _repr_(self):
    726726        return "Ring of integers modulo %s"%self.__order
     727
     728    def _hash_(self):
     729        return hash(self.__order)
    727730       
    728731    def _latex_(self):
    729732        return "\ZZ/%s\ZZ" % self.__order
  • sage/rings/ring.pyx

    diff -r 7555f009b44d -r 24ddfa703775 sage/rings/ring.pyx
    a b  
    833833            return 1
    834834        raise NotImplementedError
    835835   
    836     def __hash__(self):
    837         """
    838         EXAMPLES::
    839 
    840             sage: hash(QQ)
    841             -11115808
    842             sage: hash(ZZ)
    843             554590422
    844         """
    845         return hash(self.__repr__())
    846 
    847836    def zeta(self, n=2, all=False):
    848837        """
    849838        Return an n-th root of unity in self if there is one,
  • sage/structure/parent.pxd

    diff -r 7555f009b44d -r 24ddfa703775 sage/structure/parent.pxd
    a b  
    1919    cdef public _initial_action_list
    2020    cdef public _initial_convert_list
    2121    cdef readonly bint _coercions_used
     22
     23    cdef public long __hash
     24    cpdef long _hash_(self)
    2225   
    2326    cpdef register_coercion(self, mor)
    2427    cpdef register_action(self, action)
  • sage/structure/parent.pyx

    diff -r 7555f009b44d -r 24ddfa703775 sage/structure/parent.pyx
    a b  
    10551055        elif op == 5: #>=
    10561056            return r >= 0
    10571057
     1058    def __hash__(self):
     1059        """
     1060        The default implementation of __hash__ is to call _hash_() and cache the value.
     1061
     1062        EXAMPLES::
     1063
     1064            sage: R = Integers(3^20)
     1065            sage: hash(R)
     1066           
     1067        """
     1068        if self.__hash == 0:
     1069            self.__hash = self._hash_()
     1070        return self.__hash
     1071
     1072    cpdef long _hash_(self):
     1073        return hash(self.__repr__())
     1074
    10581075    # Should be moved and merged into the EnumeratedSets() category
    10591076    def __len__(self):
    10601077        """