From: Timo Sirainen Date: Fri, 12 Aug 2011 14:40:55 +0000 (+0300) Subject: lib-storage: Added mail_guid_128_hash/cmp() X-Git-Tag: 2.1.alpha1~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6feb0ff583c425dbe5b77ad99bc5ecbd2e508f29;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Added mail_guid_128_hash/cmp() --- diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index 486d39696f..13e553d9b9 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -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 diff --git a/src/lib-storage/mail.c b/src/lib-storage/mail.c index 860cb1f27c..c959cfd784 100644 --- a/src/lib-storage/mail.c +++ b/src/lib-storage/mail.c @@ -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); +} diff --git a/src/lib-storage/mailbox-guid-cache.c b/src/lib-storage/mailbox-guid-cache.c index 65b80033be..0e5a981216 100644 --- a/src/lib-storage/mailbox-guid-cache.c +++ b/src/lib-storage/mailbox-guid-cache.c @@ -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)