I have watched over 100 hashCode implementations.
Frequently hash code is a sum of several other hashes. Such implementation kill hash idea, it's terrible. Here is some examples public int hashCode() { int result = 0; Iterator<Map.Entry<K, V>> it = entrySet().iterator(); while (it.hasNext()) { result += it.next().hashCode(); } return result; } public int hashCode() { int i = this.addrType.hashCode(); for (int j = 0; j < this.buf.length; j++) { i += this.buf[j]; } return i; } public int hashCode() { return modifiers *+* ( keyCode != KeyEvent.VK_UNDEFINED ? len keyCode : keyChar) *+* (onKeyRelease ? -1 : 0); } public int hashCode() { return id.hashCode() + bcc.hashCode(); } and many others... also I have found such "algorithms" =) private long* *token; public int hashCode() { return (int) token; } private long objNum; public int hashCode() { return (int) objNum; } The most of hashCode() functions are implemented in different ways. It's not problem, but it looks like scrappy, there is no single style. And finally we have class *org.appache.harmony.misc.HashCode *for this aim! Example of using public int hashCode() { HashCode hash = new HashCode(); hash.append(m00); hash.append(m01); hash.append(m02); hash.append(m10); hash.append(m11); hash.append(m12); return hash.hashCode(); } public int hashCode() { HashCode hash = new HashCode(); hash.append(width); hash.append(cap); hash.append(join); hash.append(miterLimit); if (dash != null) { hash.append(dashPhase); for(int i = 0; i < dash.length; i++) { hash.append(dash[i]); } } return hash.hashCode(); } But only several classes are using it. I suggest integrate HashCode in all hashCode() implementations (about 200 files), I can do this. Anybody else can improve HashCode work. Any comments? 2006/7/26, Anton Luht <[EMAIL PROTECTED]>:
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 ). -- Regards, Anton Luht, Intel Middleware Products Division --------------------------------------------------------------------- Terms of use : http://incubator.apache.org/harmony/mailing.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Denis M. Kishenko Intel Middleware Products Division