Hi all,
I was looking at the hashCode implementation in the org.apache.clerezza.rdf.core.impl.TripleImpl and I found that this method has this code:

public int hashCode() {
return (subject.hashCode() >> 1) ^ subject.hashCode() ^ (subject.hashCode() << 1);
}

This function uses only the subject of the triple. Wondering why only one part of the triple is used, I looked at the implementation of the corresponding class in the Jena library, and I found that there the method is implemented in this way:

public int hashCode() {
return (subject.hashCode() >> 1) ^ predicate.hashCode() ^ (object.hashCode() << 1);
}

And the reason is that in this way the triple (subject, predicate, object) has a differente hash code than (object, predicate, subject).

Now, it seems to be a small bug in the TripleImpl class. This error doesn't prevent to use TripleImpl as keys in HashMaps because the corresponding equals method is correct and coherent ( a.equals(b) => a.hashCode() == b.hashCode() ), but it can yield to performance degradation when storing a lot of triples with the same subject in an HashMap.

Regards,
Giuseppe

Reply via email to