This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: question about "object"
- To: Doug Orleans <dougo at ccs dot neu dot edu>
- Subject: Re: question about "object"
- From: Per Bothner <per at bothner dot com>
- Date: 23 Mar 2001 17:05:41 -0800
- Cc: kawa at sourceware dot cygnus dot com
- References: <15035.59655.757971.411750@vega.ccs.neu.edu>
Doug Orleans <dougo@ccs.neu.edu> writes:
> Unfortunately, two lists which are equal? might not have the same hash
> code:
Could you try the cvs version? It seems to work there.
> Although it would be nice if hash codes were in fact equal for equal
> lists,
It is more than nice - it is required.
> I still need to override the equals method because the keys are
> actually lists of objects which might be circular data structures
> (which causes equal? to go into an infinite loop).
That may be more difficult. In general, it might be quite expensive
to handle self-referential structures correctly. The general trick
is you keep a table of the objects you've seen, and when you see
an object in the table, you know you have a cycle. For hashCode we
can handle circular lists by taking the hashCode of (say) the
first 10 car value. Handling equals is trickier - it might be possile
to use a variant of the list-length algorithm.
> #|kawa:27|# (define ht (make <java.util.HashMap>))
> #|kawa:28|# (invoke ht 'put (hashtable-key '(x y z)) 'xyz)
> #!null
> #|kawa:29|# (invoke ht 'containsKey (hashtable-key '(x y z)))
> #f
>
> Can anyone figure out what's going wrong here? I'm not sure how to
> debug this.
Did you verify that:
(equal? (hashtable-key '(x y z)) (hashtable-key '(x y z)))
and
(invoke (hashtable-key '(x y z) 'equals (hashtable-key '(x y z))))
--
--Per Bothner
per@bothner.com http://www.bothner.com/~per/