From: Kevin McCarthy Date: Sun, 29 Jan 2017 02:47:48 +0000 (-0800) Subject: Add hash_find_elem to get the hash element. X-Git-Tag: neomutt-20170225~33^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=778a3725a57436dbf9f7f17f40e71ec87b95fc45;p=neomutt Add hash_find_elem to get the hash element. This will be used in the following patch for directly manipulating the label counter. --- diff --git a/hash.c b/hash.c index d0a954fdc..e0f4dff68 100644 --- a/hash.c +++ b/hash.c @@ -198,7 +198,7 @@ int int_hash_insert (HASH * table, unsigned int intkey, void *data, int allow_du return union_hash_insert (table, key, data, allow_dup); } -static void *union_hash_find (const HASH *table, union hash_key key) +static struct hash_elem *union_hash_find_elem (const HASH *table, union hash_key key) { int hash; struct hash_elem *ptr; @@ -211,7 +211,7 @@ static void *union_hash_find (const HASH *table, union hash_key key) for (; ptr; ptr = ptr->next) { if (table->cmp_key (key, ptr->key) == 0) - return (ptr->data); + return (ptr); } return NULL; } @@ -233,6 +233,15 @@ void hash_set_data (HASH *table, const char *key, void *data) ptr->data = data; } +static void *union_hash_find (const HASH *table, union hash_key key) +{ + struct hash_elem *ptr = union_hash_find_elem (table, key); + if (ptr) + return ptr->data; + else + return NULL; +} + void *hash_find (const HASH *table, const char *strkey) { union hash_key key; @@ -240,6 +249,13 @@ void *hash_find (const HASH *table, const char *strkey) return union_hash_find (table, key); } +struct hash_elem *hash_find_elem (const HASH *table, const char *strkey) +{ + union hash_key key; + key.strkey = strkey; + return union_hash_find_elem (table, key); +} + void *int_hash_find (const HASH *table, unsigned int intkey) { union hash_key key; diff --git a/hash.h b/hash.h index db5006a21..b29e097ea 100644 --- a/hash.h +++ b/hash.h @@ -54,6 +54,7 @@ HASH *hash_resize (HASH * table, int nelem, int lower); int int_hash_insert (HASH *table, unsigned int key, void *data, int allow_dup); void *hash_find (const HASH *table, const char *key); +struct hash_elem *hash_find_elem (const HASH *table, const char *strkey); void *int_hash_find (const HASH *table, unsigned int key); struct hash_elem *hash_find_bucket (const HASH *table, const char *key);