Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!purdue!lerc.nasa.gov!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!news.sprintlink.net!simtel!harbinger.cc.monash.edu.au!news.cs.su.oz.au!tmx!news.tmx.com.au!news
From: s.meyn@oose.com.au (Stephan Meyn)
Subject: Re: [VW2] Help with Hash please
Message-ID: <DEtzuE.ADM@online.tmx.com.au>
Nntp-Posting-Host: ras.berry.oose.com.au
Sender: news@online.tmx.com.au (System Administrator)
Mime-Version: 1.0
Organization: Object Oriented P/L
Date: Wed, 13 Sep 1995 06:39:49 GMT
References: <2BMUwA0HBh107h@icc.shn.com>
X-Newsreader: WinVN 0.99.3
Lines: 31

In article <2BMUwA0HBh107h@icc.shn.com>, sma@icc.shn.com says...
>
>The following code will break VW2.0 which gets lost in endless recursion.
>
>| x | x := Array new: 1. x at: 1 put: x. ^x hash
>
>However, I need to store such kind of recursive arrays (of course with
>more elements) into Dictionaries. Does anybody have a solution or 
>workaround for this problem? 
>
>Thanks in advance,
>bye

Yes, you have to override the hash method. Obviously hte standard hash 
method for array involves asking the hash of all its contents.
the hash method is an optimization for the Set class. When adding an 
object to an instance of Set, the add method will check the hash of the 
object to be added with the hash of all other objects. It will then only 
do #= with those objects that yield the same hash as the object to be 
added. 
So you can actually return any value for the hash method. At worst you 
will be slowing down the Set>>add: method.

N.B. (Important) make sure that the hash method returns the correct class. 
In Enfin (and I am think it is the same in the others) it _must_ be of 
class SmallInteger. If it isn't you can get the most astounding results.

stephan
>-- 
>Stefan Matthias Aust // ...and the sun gets bloody and the sun goes down.

