Re: Hashtables



Kenneth Patrick Turvey wrote:

Whoops. I misread the source, not his comment. I looked a bit closer and with some digging I found this tidbit:

Look at the source? That's an idea.

This is the function that ends up returning the value used for
Object.hashCode().  It looks like an address, but I'm not positive.  A
jobject could be something else I guess.  I looked around in the source
and was unable to find a definitive answer in a reasonable amount of time.

In the mustang source under the hotspot directory, grepping brings up lots of stuff. It seems as if the default algorithm is to use the address at the first attempt to read hashCode. There are other algorithms for returning a shared unsynchronised random number, a thread-local random number and 1.


The address is shifted to get the good bits. Experimentation points to the hash code always being positive (just). They'll be in trouble if it generates zero. I'd be tempted to always store the initial address >> 3, or change the header (and add a trailer) when hashCode is first used and first copy after use.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.



Relevant Pages

  • Re: Problem: GetHashCode for string is different in 1.1 and 2.
    ... or even across calls to GetHashCode across different ... counter to the object reference. ... and use the MD5 or SHA1 algorithm for hashing your data. ... This is creating a big problem, because we relied on this hashcode as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Match GetHashCode between .NET 1.1 app and non-.NET app
    ... Hash algorithm should be tuned to your specific data to get the most rage of data distribution ... that you *should not* rely on a hashcode being valid outside the ... Michael Nemtsev:: blog: http://spaces.msn.com/laflour ...
    (microsoft.public.dotnet.framework.clr)
  • Re: radomize a number list
    ... > Here is a Permuted Order class to find the next permutation of any ArrayList ... > a way to get object ref int in a safe context. ... I'm concerned that your algorithm is assuming that two objects ... hashcode, I believe it will treat them as being the same, incorrectly. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Hashtables
    ... toStringand hashCode on an array of objects and keep doing it to see if they ever change. ... I expect toString() will eventually change after a GC but surely hashCode will not. ... although they have changed their algorithm as well. ...
    (comp.lang.java.help)