[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] FYI: Fixes in org.omg.CORBA.Object._is_equivalent.
From: |
Mark Wielaard |
Subject: |
Re: [cp-patches] FYI: Fixes in org.omg.CORBA.Object._is_equivalent. |
Date: |
Fri, 02 Dec 2005 15:11:18 +0100 |
Hi Audrius,
Going through some older patches.
On Sun, 2005-11-06 at 14:24 +0100, Meskauskas Audrius wrote:
> + /**
> + * Get the hashcode of this IOR.
> + */
> + public int hashCode()
> + {
> + Adler32 adler = new Adler32();
> + if (key != null)
> + adler.update(key);
> + if (Internet != null && Internet.host != null)
> + adler.update(Internet.host.getBytes());
> +
> + return (int) adler.getValue();
> }
You often use the result of an Adler32 checksum as hashCode() value.
Wouldn't it be more efficient to just simply xor the relevant fields? In
the followup patch you also correctly add the port number so in this
case it would be:
public int hashCode()
{
int hash = 0;
if (key != null)
for (int i = 0; i < key.length; i++)
hash ^= key[i];
if (Internet != null && Internet.host != null)
{
byte[] bs = Internet.host.getBytes();
for (int i = 0; i < bs.length; i++)
hash ^= bs[i];
hash ^= Internet.port;
}
return hash;
}
Which seems more efficient. But maybe that isn't a good enough hash
function in this case and maybe using Adler32 isn't that much overhead.
Just wondering why you use it.
Cheers,
Mark
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [cp-patches] FYI: Fixes in org.omg.CORBA.Object._is_equivalent.,
Mark Wielaard <=