summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2017-02-10 13:01:21 -0800
committerKevin McCarthy <kevin@8t8.us>2017-02-10 13:01:21 -0800
commit43561289acfc4fae8494794bb94f6858c1d0d3db (patch)
treee157e0a76e04de66a086cb05a247d23fa46c5cf7 /hash.c
parent63153cc6ee725e1eec5c7df8ae0e518c148cd529 (diff)
Change "allow_dups" into a flag at hash creation.
Instead of having an "allow_dups" parameter for hash_insert(), add a flag, MUTT_HASH_ALLOW_DUPS, to hash_create(). Currently ReverseAlias, subj_hash, and thread_hash allow duplicate keys. Change those hashes to pass the flag at creation, and remove the last parameter from all callers of hash_insert().
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/hash.c b/hash.c
index 40afd0b1..3747dee5 100644
--- a/hash.c
+++ b/hash.c
@@ -102,14 +102,18 @@ HASH *hash_create (int nelem, int flags)
}
if (flags & MUTT_HASH_STRDUP_KEYS)
table->strdup_keys = 1;
+ if (flags & MUTT_HASH_ALLOW_DUPS)
+ table->allow_dups = 1;
return table;
}
-HASH *int_hash_create (int nelem)
+HASH *int_hash_create (int nelem, int flags)
{
HASH *table = new_hash (nelem);
table->gen_hash = gen_int_hash;
table->cmp_key = cmp_int_key;
+ if (flags & MUTT_HASH_ALLOW_DUPS)
+ table->allow_dups = 1;
return table;
}
@@ -118,7 +122,7 @@ HASH *int_hash_create (int nelem)
* data data to associate with `key'
* allow_dup if nonzero, duplicate keys are allowed in the table
*/
-static int union_hash_insert (HASH * table, union hash_key key, void *data, int allow_dup)
+static int union_hash_insert (HASH * table, union hash_key key, void *data)
{
struct hash_elem *ptr;
unsigned int h;
@@ -128,7 +132,7 @@ static int union_hash_insert (HASH * table, union hash_key key, void *data, int
ptr->key = key;
ptr->data = data;
- if (allow_dup)
+ if (table->allow_dups)
{
ptr->next = table->table[h];
table->table[h] = ptr;
@@ -158,18 +162,18 @@ static int union_hash_insert (HASH * table, union hash_key key, void *data, int
return h;
}
-int hash_insert (HASH * table, const char *strkey, void *data, int allow_dup)
+int hash_insert (HASH * table, const char *strkey, void *data)
{
union hash_key key;
key.strkey = table->strdup_keys ? safe_strdup (strkey) : strkey;
- return union_hash_insert (table, key, data, allow_dup);
+ return union_hash_insert (table, key, data);
}
-int int_hash_insert (HASH * table, unsigned int intkey, void *data, int allow_dup)
+int int_hash_insert (HASH * table, unsigned int intkey, void *data)
{
union hash_key key;
key.intkey = intkey;
- return union_hash_insert (table, key, data, allow_dup);
+ return union_hash_insert (table, key, data);
}
static struct hash_elem *union_hash_find_elem (const HASH *table, union hash_key key)