[Kde-pim] Nepomukfeeder Caching

Christian Mollekopf chrigi_1 at fastmail.fm
Tue Dec 4 16:22:09 GMT 2012




> 
> * The hashing function simply xor's the conjunction of the hashes of uri
> and 
> value of each resource-property together to calculate the hash of the
> full 
> resource.  I don't know the math behind that but simply copied it from 
> nepomuk-core, input would be appreciated:
> propertycache.cpp:50
> 

The hashing function looks like this:

    uint hash = 0;
    QHashIterator<QUrl, QVariant> it( properties );
    while( it.hasNext() ) {
        it.next();
        hash ^= qHash( it.key() ) & qHash( it.value().toString() );
    }
    return hash;

The (hash ^= newhash) should be ok, but I don't think the conjunction
is, and I think it would make more sense to XOR that as well. That the
hash is initialized with 0 doesn't hurt IMO as there is a 50/50 chance
we for 0 or 1 when using an XOR.

So I'll change this to:

    uint hash = 0;
    QHashIterator<QUrl, QVariant> it( properties );
    while( it.hasNext() ) {
        it.next();
        hash ^= qHash( it.key() ) ^ qHash( it.value().toString() );
    }
    return hash;

Note that XOR is commutative, so the hash does not preserve the
information of order, but that should be fine for our usecase.
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list