help!! - now "Hash the set"

Andreas Raab raab at isgnw.cs.Uni-Magdeburg.DE
Fri Apr 17 10:02:46 UTC 1998


>     Q: What if the hash of anObject changes while it's included in aSet?
>     A: The hash will no longer be valid.
>     Ex:
>         aSet _ Set new add: (bSet _ Set new).
> 		cSet _ Set new add: (dSet _ Set new).
> 		aSet = cSet. <Alt-p> true
> 		aSet hash = cSet hast. <Alt-p> true
> 		bSet add: 1.
> 		aSet = cSet. <Alt-p> false
> 		aSet hash = cSet hash. <Alt-p> true
> 		"Ups!"

Bad example. It's ok for hashes to be equal if objects are *not* equal.
Hashes are only required to be equal iff the objects are equal.
Unless you do a #become: the scheme is entirely correct.

> 	All this makes me think that using Objects whos hashes can change
> through time is not good at all for keys or indices, becouse if you, or
> aDictionary, are using hashes to locate keys, may be that you would not
> find an existing key. Be careful with this!

Absolutely right. I've never seen a case where using a collection as key
would *really* be necessary.

Andreas
-- 
Linear algebra is your friend - Trigonometry is your enemy.
+===== Andreas Raab ============= (raab at isg.cs.uni-magdeburg.de) =====+
I Department of Simulation and Graphics      Phone: +49 391 671 8065  I
I University of Magdeburg, Germany           Fax:   +49 391 671 1164  I
+=============< http://isgwww.cs.uni-magdeburg.de/~raab >=============+





More information about the Squeak-dev mailing list