harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Denis Kishenko" <dkishe...@gmail.com>
Subject Re: Re: [optimization] Algorithmic tricks
Date Thu, 27 Jul 2006 09:29:01 GMT
2006/7/26, Alex Blewitt <alex.blewitt@gmail.com>:
> There are other approaches that could be used instead of this. For
> example, the value of the hashCode could be cached in a private
> variable and then invalidated when any setValue() methods are called.
> One could even imagine a superclass performing this caching work:
>
> public abstract class HashCode {
>  private boolean valid = false;
>  private int hash;
>  public final int hashCode() {
>    if (!valid) {
>      hash = recalculateHashCode();
>      valid = true;
>    }
>    return hash;
>  }
>  protected abstract int recalculateHash();
>  protected void invalidate() { valid = false; }
> }
>
> Of course, you could use the HashCode object to calculate the hash value :-)
Unfortunately
1. class can has temporary private fields (see BasicStroke.java)
2. class can has final fields which take part in hash code calculation
(see EllipticCurve.java)

-- 
Denis M. Kishenko
Intel Middleware Products Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message