incubator-clerezza-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reto Bachmann-Gmür <r...@apache.org>
Subject Re: Small bug in the TripleImple implementation
Date Fri, 04 Jan 2013 10:59:27 GMT
On Fri, Jan 4, 2013 at 10:22 AM, Giuseppe Miscione <
g.miscione@innovationengineering.eu> wrote:

> Hi Reto,
> why this will affect also the interface?
>

Because it's defined wrongly in the the javadoc comment for hashCode in the
triple interface. The comments needs to be fixed.

Cheers,
Reto

>
> Il 04/01/2013 10:17, Reto Bachmann-Gmür ha scritto:
>
>  Yes, I confirm. Thanks Giuseppe.
>> The bug affects the interface definition of Triple, not just the
>> implementation.
>>
>> Cheers,
>> Reto
>>
>> On Fri, Jan 4, 2013 at 10:06 AM, Tommaso Teofili
>> <tommaso.teofili@gmail.com>**wrote:
>>
>>  Hi Giuseppe,
>>>
>>> thanks a lot! This seems to me to be a bug (if anyone else feels I'm
>>> wrong
>>> please chime in), feel free to open a Jira issue on
>>> https://issues.apache.org/**jira/browse/CLEREZZA<https://issues.apache.org/jira/browse/CLEREZZA>and
eventually attach a
>>> patch.
>>>
>>> Thanks again and have a nice day!
>>> Tommaso
>>>
>>>
>>> 2013/1/4 Giuseppe Miscione <g.miscione@**innovationengineering.eu<g.miscione@innovationengineering.eu>
>>> >
>>>
>>>  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
>>>>
>>>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message