Re: Fast union/intersection of two sequences?

Marc Wachowitz (mw@ipx2.rz.uni-mannheim.de)
25 Jan 1995 08:39:58 GMT

Guido wrote:
> As a final warning, *if* a class defines a __hash__, it has the
> responsibility to be immutable. If you violate this rule, it is
> possible to use an object as a dictionary key, and then change it,
> after which it may become impossible to find it back in the
> dictionary...

Just in case someone reads this paragraph without thinking much about it
(not intended to belittle anyone, but empirically such things happen ;-)
I'd like to mention that of course only those aspects of the key need to
be immutable which would otherwise change the hash value. It's like some
primary key in a database, which is crucial to referential integrity. An
attribute which doesn't contribute to the hash value, or is only changed
to another value with the same hash value - e.g. for optimizations which
remain hidden to the client of an abstract data type - would be okay. It
is often possible to carefully design a hash function that works in such
cases.

------------------------------------------------------------------------------
* wonder everyday * nothing in particular * all is special *
Marc Wachowitz <mw@ipx2.rz.uni-mannheim.de>