[jdom-interest] AttributeList performance

Elliotte Harold elharo at metalab.unc.edu
Thu Apr 28 03:25:16 PDT 2005


Victor Toni wrote:

> Maybe something like this (which could be still optimized if called often):
> 
>     public final int hashCode() {
>         return name.hashCode() * 29 + namespace.hashCode();
>     }

This would be inappropriate for a general purpose hashCode method 
because it would lead to numerous hash collisions. For instance, all the 
id attributes in every document would have the same hash, regardless of 
their distinct values.

A better solution would be to use the attributes' qualified names 
(unique within any one attribute) as the key into the hash table rather 
than the Attribute objects themselves.

Again, however, I doubt the overhead justifies the "optimization". 
Barring hard evidence to the contrary, I think the the current approach 
is faster and should be preferred.

-- 
Elliotte Rusty Harold  elharo at metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim


More information about the jdom-interest mailing list