harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Gray <chris.g...@kiffer.be>
Subject Re: [optimization] Algorithmic tricks
Date Mon, 31 Jul 2006 11:22:06 GMT
On Wednesday 26 July 2006 13:03, Anton Luht wrote:
> Hello,
> One of possible candidates for such optimization may be for example
> String.hashCode() . Current implementation is rather common. Wikipedia
> points to hash functions that look more advanced (
> http://en.wikipedia.org/wiki/Hash_function ).

Seems to me that String.hashCode() has to use the algorithm described in the 
spec if it's to be compliant. An application which relied on known values of 
hashCode() might be stupid, but it would be according to contract.
  switch(opcode.hashCode()) {
      case NOP_HASH_CODE:  do_nop();
      case ALOAD0_HASH_CODE: do_aload0();

You could consider using a better hashcode for e.g. string interning (private 
ind internalHashCode() {...}); if your internal hashcode is both faster and 
better than the "official" one then that's a clear win. But as has been 
pointed out elsewhere in this thread, in general it's a trade-off between the 
effort required to calculate the hashcode and the collision rate in the 
hashtable. No point in having a world-beating hash function for a table which 
is s small that linear search would be fast enough ...


Chris Gray        /k/ Embedded Java Solutions      BE0503765045
Embedded & Mobile Java, OSGi    http://www.k-embedded-java.com/
chris.gray@kiffer.be                             +32 3 216 0369

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

View raw message