From: Josef Eschgfaeller
Subject: Re: Equality of hash tables
Date: 
Message-ID: <37A8B5AB.778B7051@felix.unife.it>
Bernhard Pfahringer wrote:

> Additionally, using modifyable structures as hash-table keys
> can be dangerous: if the structure is modified, its hash-code
> might change as well.

Since any object can be a key of a hash table, are it not only
the pointers which are used?

je

From: Tim Bradshaw
Subject: Re: Equality of hash tables
Date: 
Message-ID: <ey3907rkwo4.fsf@lostwithiel.tfeb.org>
* Josef Eschgfaeller wrote:

> Since any object can be a key of a hash table, are it not only
> the pointers which are used?

No, because hash tables can hash on EQUAL as well as EQL (which is
fairly close to pointer equality).  Two objects can be EQUAL but not
EQL.

--tim
From: Bernhard Pfahringer
Subject: Re: Equality of hash tables
Date: 
Message-ID: <7oakq6$c3a$1@www.univie.ac.at>
In article <·················@felix.unife.it>,
Josef Eschgfaeller  <···@felix.unife.it> wrote:
>Bernhard Pfahringer wrote:
>
>> Additionally, using modifyable structures as hash-table keys
>> can be dangerous: if the structure is modified, its hash-code
>> might change as well.
>
>Since any object can be a key of a hash table, are it not only
>the pointers which are used?
>

I don't think so. E.g in CLISP the equal hash code of a bit-vector is
computed from the length and the first and the last 16 bits
respectively (if I understood that code correctly). You could
not just use the pointers for EQUAL, as obviously pointers to equal-but-
not-eq structures would be different and would most probably lead to 
differing hash-codes.

BTW, I did not want to imply that one should not use modifyable structures
as hash-table keys, I only wanted to raise awareness of the implications
that can lead to hard-to-find bugs if one is not careful when using
such keys (yes, I got myself into that situation once :-(

Bernhard
-- 
--------------------------------------------------------------------------
Bernhard Pfahringer
Austrian Research Institute for  http://www.ai.univie.ac.at/~bernhard/
Artificial Intelligence          ········@ai.univie.ac.at 
From: Thomas A. Russ
Subject: Re: Equality of hash tables
Date: 
Message-ID: <ymivhajzauu.fsf@sevak.isi.edu>
Josef Eschgfaeller <···@felix.unife.it> writes:
> Bernhard Pfahringer wrote:
> 
> > Additionally, using modifyable structures as hash-table keys
> > can be dangerous: if the structure is modified, its hash-code
> > might change as well.
> 
> Since any object can be a key of a hash table, are it not only
> the pointers which are used?

No, since the pointers can change as well.  Most modern Lisp
implementations now use copying garbage collectors which move objects.
That means that the machine address of a pointer is not an invariant
property of the object that it points to.  It would be rather grim if GC
forced all hashtables to rehash, so the hash value must be computed from
something other than the pointer to the object.


-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu