Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!travelers.mail.cornell.edu!news.kei.com!newshost.marcam.com!usc!howland.reston.ans.net!xlink.net!ins.net!heeg.de!hasko
From: hasko@heeg.de (Hasko Heinecke)
Subject: Re: [VW2] Help with Hash please
Message-ID: <DF9AoB.9KK@heeg.de>
Sender: uucp@heeg.de
Organization: Georg Heeg Objektorientierte Systeme, Dortmund, FRG
X-Newsreader: TIN [version 1.2 PL2]
References: <2BMUwA0HBh107h@icc.shn.com> <DEtzuE.ADM@online.tmx.com.au>
Date: Thu, 21 Sep 1995 12:57:46 GMT
Lines: 33

Stephan Meyn (s.meyn@oose.com.au) wrote:
: 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.

No, it doesn't. Imagine what would happen with a 1,000,000 elements array.
Hashing is supposed to be _fast_. :-)

So, actually, Array only use their _first_ element's hash value to calculate
their own. I haven't tried if changing that breaks the system, but maybe you
can simply leave out the dirst element. Anyway, defining a proper class for
wht you are doing would be the best solution.

Regards,

Hasko
--
+------------------------------------------------------+
| Hasko Heinecke, Georg Heeg - Object-Oriented Systems |
| hasko@heeg.de or http://www.heeg.de/~hasko           |
+------------------------------------------------------+
