def __hash__(self): """Return a hash based on the value that is calculated on demand and cached.""" if not self._hash: counter_parts = self.data.items() multiset_parts = ['algebraixlib.mathobjects.multiset.Multiset'] # noinspection PyTypeChecker multiset_parts.extend(counter_parts) self._hash = _get_hash(*multiset_parts) return self._hash
def __init__(self, value, direct_load=False): """Construct an instance with the given ``value``. :param value: The value of the :class:`Atom`. May not be an instance of `MathObject` other than :class:`Atom`. (If it is of type :class:`Atom`, this :class:`Atom` is used.) The ``value`` must be immutable and hashable. """ if hasattr(self, '_value'): return # Already initialized super().__init__() if direct_load: assert not isinstance(value, MathObject) else: if isinstance(value, MathObject): raise TypeError("'value' must not be a MathObject") self._value = value # NOTE: Non-hashable values will generate TypeError..including Undef() self._hash = _get_hash('algebraixlib.mathobjects.atom.Atom', self._value)
def __init__(self, value, direct_load=False): """ :param value: The value of this instance. May not be an instance of `MathObject` other than :class:`Atom`. (If it is of type :class:`Atom`, the instance is re-used; see `__new__`.) ``value`` must be immutable and hashable. :param direct_load: Set to ``True`` if you can be sure that ``value`` is not an instance of `MathObject`. Default is ``False``. :raise: `TypeError` if ``value`` is not hashable. """ # Check whether we received an already initialized instance (by __new__). if hasattr(self, '_value'): return super().__init__(self._INIT_CACHE) if direct_load: assert not isinstance(value, MathObject) else: if isinstance(value, MathObject): raise TypeError("'value' must not be a MathObject") self._value = value self._hash = _get_hash('algebraixlib.mathobjects.atom.Atom', self._value)
def __hash__(self): """Return a hash based on the value that is calculated on demand and cached.""" if not self._hash: self._hash = _get_hash('algebraixlib.mathobjects.couplet.Couplet', self.left, self.right) return self._hash
def __hash__(self): """Return a hash based on the member values. (It must match the implementation of `is_same`, to which `Structure.__eq__` redirects equality comparisons.) Is always cached. """ return _get_hash(_get_full_class_name(self), self.base_set)