harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Petrenko" <alexey.a.petre...@gmail.com>
Subject Re: Re: [optimization] Algorithmic tricks
Date Fri, 28 Jul 2006 09:30:43 GMT
2006/7/27, Denis Kishenko <dkishenko@gmail.com>:
> 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)
We can mark such fields as transient. As for serialization.

> 2. class can has final fields which take part in hash code calculation
> (see EllipticCurve.java)
It's probably the reason to add final fields to hash code calculation.

SY, Alexey

-- 
Alexey A. Petrenko
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