{"id":76,"date":"2008-01-17T12:25:26","date_gmt":"2008-01-17T19:25:26","guid":{"rendered":"http:\/\/thesmithfam.org\/blog\/2008\/01\/17\/using-qrect-with-qhash\/"},"modified":"2019-08-12T07:16:12","modified_gmt":"2019-08-12T13:16:12","slug":"using-qrect-with-qhash","status":"publish","type":"post","link":"https:\/\/thesmithfam.org\/blog\/2008\/01\/17\/using-qrect-with-qhash\/","title":{"rendered":"Using QRect with QHash"},"content":{"rendered":"<p>In Qt 4.3.3, I found myself needing to use QRect instances as a key in a QHash. However, Trolltech provides no qHash() implementation for QRect, so I implemented this one, and I think it ought to cover the most common uses of QRect. What do you think?<\/p>\n<p>uint qHash(const QRect &#038;rect)<br \/>\n{<br \/>\n    uint code = 0;<\/p>\n<p>    code |= (rect.x() < < 16);\n    code |= (rect.y() &#038; 0x0000ffff);\n    code ^= (rect.width() << 16);\n    code ^= (rect.height() &#038; 0x0000ffff);\n\n    return code;\n}[\/code]\n\nPreliminary testing seems indicates that it produces a fairly good distribution of hash codes. In this case, I'm defining \"fairly good\" as, \"I haven't seen any collisions on the few rectangles I've tried.\" :)\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Qt 4.3.3, I found myself needing to use QRect instances as a key in a QHash. However, Trolltech provides no qHash() implementation for QRect, so I implemented this one, and I think it ought to cover the most common uses of QRect. What do you think? uint qHash(const QRect &#038;rect) { uint code = [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-code-and-cruft"],"_links":{"self":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":1,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":1572,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/76\/revisions\/1572"}],"wp:attachment":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}