for (ap = t->addr; ap; ap = ap->next)
{
if (!ap->group && ap->mailbox)
- hash_insert (ReverseAlias, ap->mailbox, ap, 1);
+ hash_insert (ReverseAlias, ap->mailbox, ap);
}
}
dprint (2, (debugfile, "mutt_pattern_group: Creating group %s.\n", k));
p = safe_calloc (1, sizeof (group_t));
p->name = safe_strdup (k);
- hash_insert (Groups, p->name, p, 0);
+ hash_insert (Groups, p->name, p);
}
return p;
}
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;
}
* 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;
ptr->key = key;
ptr->data = data;
- if (allow_dup)
+ if (table->allow_dups)
{
ptr->next = table->table[h];
table->table[h] = ptr;
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)
typedef struct
{
int nelem;
- int strdup_keys; /* if set, the key->strkey is strdup'ed */
+ unsigned int strdup_keys : 1; /* if set, the key->strkey is strdup'ed */
+ unsigned int allow_dups : 1; /* if set, duplicate keys are allowed */
struct hash_elem **table;
unsigned int (*gen_hash)(union hash_key, unsigned int);
int (*cmp_key)(union hash_key, union hash_key);
/* flags for hash_create() */
#define MUTT_HASH_STRCASECMP (1<<0) /* use strcasecmp() to compare keys */
#define MUTT_HASH_STRDUP_KEYS (1<<1) /* make a copy of the keys */
+#define MUTT_HASH_ALLOW_DUPS (1<<2) /* allow duplicate keys to be inserted */
-HASH *hash_create (int nelem, int lower);
-HASH *int_hash_create (int nelem);
+HASH *hash_create (int nelem, int flags);
+HASH *int_hash_create (int nelem, int flags);
-int hash_insert (HASH * table, const char *key, void *data, int allow_dup);
-int int_hash_insert (HASH *table, unsigned int key, void *data, int allow_dup);
+int hash_insert (HASH * table, const char *key, void *data);
+int int_hash_insert (HASH *table, unsigned int key, void *data);
void *hash_find (const HASH *table, const char *key);
struct hash_elem *hash_find_elem (const HASH *table, const char *strkey);
if (!elem)
{
count = 1;
- hash_insert(ctx->label_hash, label, (void *)count, 0);
+ hash_insert(ctx->label_hash, label, (void *)count);
return;
}
ctx = idata->ctx;
if (!idata->uid_hash)
- idata->uid_hash = int_hash_create (MAX (6 * ctx->msgcount / 5, 30));
+ idata->uid_hash = int_hash_create (MAX (6 * ctx->msgcount / 5, 30), 0);
for (msgno = oldmsgcount; msgno < ctx->msgcount; msgno++)
{
h = ctx->hdrs[msgno];
- int_hash_insert (idata->uid_hash, HEADER_DATA(h)->uid, h, 0);
+ int_hash_insert (idata->uid_hash, HEADER_DATA(h)->uid, h);
}
}
Groups = hash_create (1031, 0);
/* reverse alias keys need to be strdup'ed because of idna conversions */
- ReverseAlias = hash_create (1031, MUTT_HASH_STRCASECMP | MUTT_HASH_STRDUP_KEYS);
+ ReverseAlias = hash_create (1031, MUTT_HASH_STRCASECMP | MUTT_HASH_STRDUP_KEYS |
+ MUTT_HASH_ALLOW_DUPS);
mutt_menu_init ();
mutt_srandom ();
{
maildir_canon_filename (buf, p->h->path, sizeof (buf));
p->canon_fname = safe_strdup (buf);
- hash_insert (fnames, p->canon_fname, p, 0);
+ hash_insert (fnames, p->canon_fname, p);
}
/* check for modifications and adjust flags */
{
/* the hash key must survive past the header, which is freed below. */
p->canon_fname = safe_strdup (p->h->path);
- hash_insert (fnames, p->canon_fname, p, 0);
+ hash_insert (fnames, p->canon_fname, p);
}
for (i = 0; i < ctx->msgcount; i++)
/* add this message to the hash tables */
if (ctx->id_hash && h->env->message_id)
- hash_insert (ctx->id_hash, h->env->message_id, h, 0);
+ hash_insert (ctx->id_hash, h->env->message_id, h);
if (ctx->subj_hash && h->env->real_subj)
- hash_insert (ctx->subj_hash, h->env->real_subj, h, 1);
+ hash_insert (ctx->subj_hash, h->env->real_subj, h);
mutt_label_hash_add (ctx, h);
if (option (OPTSCORE))
mutt_free_envelope (&h->env);
h->env = mutt_read_rfc822_header (msg->fp, h, 0, 0);
if (ctx->subj_hash && h->env->real_subj)
- hash_insert (ctx->subj_hash, h->env->real_subj, h, 1);
+ hash_insert (ctx->subj_hash, h->env->real_subj, h);
mutt_label_hash_add (ctx, h);
h->data = uidl;
init = 1;
if (init)
- ctx->thread_hash = hash_create (ctx->msgcount * 2, 0);
+ ctx->thread_hash = hash_create (ctx->msgcount * 2, MUTT_HASH_ALLOW_DUPS);
/* we want a quick way to see if things are actually attached to the top of the
* thread tree or if they're just dangling, so we attach everything to a top
cur->thread = thread;
hash_insert (ctx->thread_hash,
cur->env->message_id ? cur->env->message_id : "",
- thread, 1);
+ thread);
if (new)
{
if ((new = hash_find (ctx->thread_hash, ref->data)) == NULL)
{
new = safe_calloc (1, sizeof (THREAD));
- hash_insert (ctx->thread_hash, ref->data, new, 1);
+ hash_insert (ctx->thread_hash, ref->data, new);
}
else
{
{
hdr = ctx->hdrs[i];
if (hdr->env->message_id)
- hash_insert (hash, hdr->env->message_id, hdr, 0);
+ hash_insert (hash, hdr->env->message_id, hdr);
}
return hash;
HEADER *hdr;
HASH *hash;
- hash = hash_create (ctx->msgcount * 2, 0);
+ hash = hash_create (ctx->msgcount * 2, MUTT_HASH_ALLOW_DUPS);
for (i = 0; i < ctx->msgcount; i++)
{
hdr = ctx->hdrs[i];
if (hdr->env->real_subj)
- hash_insert (hash, hdr->env->real_subj, hdr, 1);
+ hash_insert (hash, hdr->env->real_subj, hdr);
}
return hash;