[Qt-interest] QString ot QUuid for QHash and QMap keys?
Giuseppe D'Angelo
dangelog at gmail.com
Sat Oct 22 01:13:51 CEST 2011
On 21 October 2011 18:08, Jason H <scorp1us at yahoo.com> wrote:
> I am wondering which if the following results in fastest lookups. I've got
> about 500-100o items in the collection, and I will constantly be doing
> lookups as the system gets the UUID for an object then proceeds to
> manipulate that object potentially several times a second, for each object.
> QMap<QUuid, QObject*>
> QHash<QUuid, QObject*>
> QMap<QString, QObject*>
> QHash<QString, QObject*>
>
> Where the string keys are a QUuid::toString().mid(1,36) (trims the curley
> braces).
For such a small number of items It's silly to talk about asymptotic
complexities. You should simply do benchmarks. operator< for QUUid is
going to be cheaper than just doing toString() conversions and mid
which involve several heap allocations/deallocations...
By the way, note that there is no qHash(QUuid) function in Qt 4 -- it
was added in Qt 5 [1]. What's actually getting called is
qHash(QString) due to the casting operator QString in QUuid, which is
*very* expensive compared to hashing somehow the UUID contents (f.i.
XORing them together). And no, it's not possible to add it in Qt4
since it would break binary compatibility :-(
>
> Also, why isn't there a toString() version that will just give me a string
> without the braces? I keep making Uuids, converting them to strings and
> cutting the braces off.
Submit a patch adding the overload (with a formatting option as argument)?
--
Giuseppe D'Angelo
[1] 55d68a1 in qtbase
More information about the Qt-interest-old
mailing list