Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!howland.reston.ans.net!Germany.EU.net!Frankfurt.Germany.EU.net!news.maz.net!ins.net!heeg.de!uucp
From: Hasko Heinecke <hasko@heeg.de>
Subject: Re: sets of objects
Content-Type: text/plain; charset=us-ascii
Message-ID: <311B6D26.695678E2@heeg.de>
Sender: uucp@heeg.de
Content-Transfer-Encoding: 7bit
Organization: Georg Heeg - Object-Oriented Systems
References: <4fd1f5$pir@iii2.iii.net>
Mime-Version: 1.0
Date: Fri, 9 Feb 1996 15:49:58 GMT
X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3 sun4c)
Lines: 25

Robert M Rogers Jr wrote:
> What must be implemented to allow the Set class to understand when anObject
> is already contained in the set. Expected behaviour is observed for
> integers and strings but application objects are not.

You have to override the message "=", which defaults to

	Object>= anObject
	  ^self == anObject

and thus only answers true if both objects are _identical_. You have to
implement your idea of equality yourself. Beware of cycles if you decide
to recursively descend instance variables!

Also, you _must_ override "hash" to return the same number for equal
objects, i.e. logically speaking:

	for all a,b: a = b => a hash = b hash

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