[gclist] object hash codes and copying collection

Mark Tillotson markt@harlequin.co.uk
Wed, 10 Dec 1997 17:02:43 GMT


Eliot Moss <moss@rhea.cs.umass.edu> wrote:
| 
| My understanding of the Java hashCode feature is that it must meet these hard
| requirements:
|   - Every object has a UNIQUE hash code
|   - An object's hash code never changes during the object's lifetime

Your first requirement is provably bogus.  On a 64-bit machine you
might have more than 2^32 distinct objects, yet hashCode() returns int, which
is 32 bit.

The second requirement is currently imposed by the simple way that
java.util.Hashtable uses the hashCode().  This is plausibly something
that might change in the future.

| One approach I suggest for this is to assign hash codes from a simple counter,
| incremented each time you assign a hash code. This does have a significant
| problem, though: in a long running program, the counter can wrap around. I
| have not thought of any good ways to fix this. It would not be an issue on a

This is not a problem, because you are trying to meet a bogus
requirement...


__Mark
[ markt@harlequin.co.uk | http://www.harlequin.co.uk/ | +44(0)1954 785433 ]