On 16 Aug 2003 05:29:03 -0700,
(Harald Kirsch) wrote
or quoted :
>I hoped someone
>came up with an ingenious idea of how to borrow String.hashcode() and and
>String.equals() and apply it to StringBuffer without rewriting everything.
A few thoughts:
1. You can't change the lookup hashCode of an object in a HashMap on
the fly. You have to remove it, change the fields the hashCode
depends on and re-add it. HashMap presumes the hashCode won't change.
2. You would likely want to cache it since it is expensive to compute.
3. If the StringBuffer is changing all the time, you might want a
faster but lower quality algorithm, or perhaps even one that just
looks at the first few characters to speed computation. You don't
need to recompute it if the first few chars don't change.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See
http://mindprod.com/jgloss/jgloss.html for The Java Glossary.