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

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to