]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added mail_guid_128_hash/cmp()
authorTimo Sirainen <tss@iki.fi>
Fri, 12 Aug 2011 14:40:55 +0000 (17:40 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 12 Aug 2011 14:40:55 +0000 (17:40 +0300)
src/lib-storage/mail-storage.h
src/lib-storage/mail.c
src/lib-storage/mailbox-guid-cache.c

index 486d39696f133ac9c846ee59c0d025508c08300e..13e553d9b912889c5af5de4c3e429f5891018a93 100644 (file)
@@ -756,4 +756,8 @@ bool mail_guid_128_is_empty(const uint8_t guid_128[MAIL_GUID_128_SIZE]);
 /* Returns GUID as a hex string. */
 const char *mail_guid_128_to_string(const uint8_t guid_128[MAIL_GUID_128_SIZE]);
 
+/* guid_128 hash/cmp functions for hash.h */
+unsigned int mail_guid_128_hash(const void *p);
+int mail_guid_128_cmp(const void *p1, const void *p2);
+
 #endif
index 860cb1f27cc6af9c738e1664aca1330b9c08508e..c959cfd784346ba234e89cfb92a4f9632d013308 100644 (file)
@@ -374,3 +374,17 @@ const char *mail_guid_128_to_string(const uint8_t guid_128[MAIL_GUID_128_SIZE])
 {
        return binary_to_hex(guid_128, MAIL_GUID_128_SIZE);
 }
+
+unsigned int mail_guid_128_hash(const void *p)
+{
+       const uint8_t *guid = p;
+
+       return mem_hash(guid, MAIL_GUID_128_SIZE);
+}
+
+int mail_guid_128_cmp(const void *p1, const void *p2)
+{
+       const uint8_t *g1 = p1, *g2 = p2;
+
+       return memcmp(g1, g2, MAIL_GUID_128_SIZE);
+}
index 65b80033be0d916760e5a47e11d2d62bc9a7df64..0e5a9812166a8fe2116ab0cbcfb9960451e59e4d 100644 (file)
@@ -14,16 +14,8 @@ struct mailbox_guid_cache_rec {
 static unsigned int guid_cache_rec_hash(const void *_rec)
 {
        const struct mailbox_guid_cache_rec *rec = _rec;
-       unsigned int i, g, h = 0;
 
-       for (i = 0; i < sizeof(rec->guid); i++) {
-               h = (h << 4) + rec->guid[i];
-               if ((g = h & 0xf0000000UL)) {
-                       h = h ^ (g >> 24);
-                       h = h ^ g;
-               }
-       }
-       return h;
+       return mem_hash(rec->guid, sizeof(rec->guid));
 }
 
 static int guid_cache_rec_cmp(const void *_r1, const void *_r2)