err.data = error;
err.dsize = sizeof(error);
- ConfigOptions = hash_create (sizeof(MuttVars) * 2);
+ ConfigOptions = hash_create (sizeof(MuttVars) * 2, 0);
for (i = 0; MuttVars[i].option; i++) {
- hash_insert (ConfigOptions, MuttVars[i].option, &MuttVars[i], 0);
+ hash_insert (ConfigOptions, MuttVars[i].option, &MuttVars[i]);
}
/*
return (h % n);
}
-HASH *hash_create(int nelem)
+HASH *hash_create(int nelem, int allow_dup)
{
HASH *table = p_new(HASH, 1);
- if (nelem == 0)
- nelem = 2;
-
- table->nelem = nelem;
+ table->dupes = allow_dup;
+ table->nelem = MIN(nelem, 2);
table->curnelem = 0;
- table->table = p_new(struct hash_elem *, nelem);
+ table->table = p_new(struct hash_elem *, table->nelem);
+
return table;
}
-HASH *hash_resize(HASH *ptr, int nelem)
+void hash_resize(HASH *ptr, int nelem)
{
HASH *table;
struct hash_elem *elem, *tmp;
int i;
- table = hash_create (nelem);
+ /* XXX hack: we know the has was correct, no dupe checks is fater */
+ table = hash_create(nelem, 1);
for (i = 0; i < ptr->nelem; i++) {
for (elem = ptr->table[i]; elem;) {
tmp = elem;
elem = elem->next;
- hash_insert(table, tmp->key, tmp->data, 1);
+ hash_insert(table, tmp->key, tmp->data);
p_delete(&tmp);
}
}
- p_delete(&ptr->table);
- p_delete(&ptr);
- return table;
+ p_delete(&ptr->table);
+ ptr->nelem = table->nelem;
+ ptr->table = table->table;
+ p_delete(&table);
}
/* table hash table to update
* data data to associate with `key'
* allow_dup if nonzero, duplicate keys are allowed in the table
*/
-int hash_insert(HASH *table, const char *key, void *data, int allow_dup)
+int hash_insert(HASH *table, const char *key, void *data)
{
struct hash_elem *ptr;
int h;
ptr->key = key;
ptr->data = data;
- if (allow_dup) {
+ if (table->dupes) {
ptr->next = table->table[h];
table->table[h] = ptr;
table->curnelem++;
};
typedef struct {
- int nelem, curnelem;
+ unsigned dupes : 1;
+ int nelem;
+ int curnelem;
struct hash_elem **table;
} HASH;
#define hash_delete(table,key,data,destroy) \
hash_delete_hash(table, hash_string((unsigned char *)key, table->nelem), key, data, destroy)
-HASH *hash_create(int nelem);
+HASH *hash_create(int nelem, int allow_dup);
int hash_string(const unsigned char *s, int n);
-int hash_insert(HASH *table, const char *key, void *data, int allow_dup);
-HASH *hash_resize(HASH *table, int nelem);
+int hash_insert(HASH *table, const char *key, void *data);
+void hash_resize(HASH *table, int nelem);
void *hash_find_hash(const HASH *table, int hash, const char *key);
void hash_delete_hash(HASH *table, int hash, const char *key,
const void *data, void (*destroy)(void *));
* of each message we scanned. This is used in the loop over the
* existing messages below to do some correlation.
*/
- fnames = hash_create (1031);
+ fnames = hash_create (1031, 0);
for (p = md; p; p = p->next) {
maildir_canon_filename (buf, p->h->path, sizeof (buf));
p->canon_fname = m_strdup(buf);
- hash_insert (fnames, p->canon_fname, p, 0);
+ hash_insert (fnames, p->canon_fname, p);
}
/* check for modifications and adjust flags */
mhs_free_sequences (&mhs);
/* check for modifications and adjust flags */
- fnames = hash_create (1031);
+ fnames = hash_create (1031, 0);
for (p = md; p; p = p->next)
- hash_insert (fnames, p->h->path, p, 0);
+ hash_insert (fnames, p->h->path, p);
for (i = 0; i < ctx->msgcount; i++) {
ctx->hdrs[i]->active = 0;
/* 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->counting) {
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);
if (option (OPTSCORE))
mutt_score_message (ctx, h, 0);
data->nserv = news;
data->deleted = 1;
if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
- news->newsgroups =
hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
- hash_insert (news->newsgroups, data->group, data, 0);
+ hash_insert (news->newsgroups, data->group, data);
nntp_add_to_list (news, data);
}
else
data->nserv = news;
data->deleted = 1;
if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
- news->newsgroups =
hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
- hash_insert (news->newsgroups, data->group, data, 0);
+ hash_insert (news->newsgroups, data->group, data);
nntp_add_to_list (news, data);
}
data->cache = m_strdup(file);
serv = p_new(NNTP_SERVER, 1);
serv->conn = conn;
serv->newsrc = m_strdup(file);
- serv->newsgroups = hash_create (1009);
+ serv->newsgroups = hash_create(1009, false);
slurp_newsrc (serv); /* load .newsrc */
nntp_parse_cacheindex (serv); /* load .index */
if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
data->nserv = news;
data->deleted = 1;
if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
- news->newsgroups =
hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
- hash_insert (news->newsgroups, data->group, data, 0);
+ hash_insert (news->newsgroups, data->group, data);
nntp_add_to_list (news, data);
}
if (!data->subscribed) {
nntp_data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1);
nntp_data->group = (char *) nntp_data + sizeof (NNTP_DATA);
strcpy (nntp_data->group, buf);
- hash_insert (serv->newsgroups, nntp_data->group, nntp_data, 0);
+ hash_insert (serv->newsgroups, nntp_data->group, nntp_data);
nntp_add_to_list (serv, nntp_data);
}
ctx->data = nntp_data;
strcpy (nntp_data->group, group);
nntp_data->nserv = s;
if (s->newsgroups->nelem < s->newsgroups->curnelem * 2)
- s->newsgroups = hash_resize (s->newsgroups, s->newsgroups->nelem * 2);
- hash_insert (s->newsgroups, nntp_data->group, nntp_data, 0);
+ hash_resize (s->newsgroups, s->newsgroups->nelem * 2);
+ hash_insert (s->newsgroups, nntp_data->group, nntp_data);
nntp_add_to_list (s, nntp_data);
}
nntp_data->deleted = 0;
init = 1;
if (init)
- ctx->thread_hash = hash_create (ctx->msgcount * 2);
+ ctx->thread_hash = hash_create (ctx->msgcount * 2, 1);
/* 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->duplicate_thread)
if ((new = hash_find (ctx->thread_hash, ref->data)) == NULL) {
new = p_new(THREAD, 1);
- hash_insert (ctx->thread_hash, ref->data, new, 1);
+ hash_insert (ctx->thread_hash, ref->data, new);
}
else {
if (new->duplicate_thread)
HEADER *hdr;
HASH *hash;
- hash = hash_create (ctx->msgcount * 2);
+ hash = hash_create (ctx->msgcount * 2, 0);
for (i = 0; i < ctx->msgcount; i++) {
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);
+ hash = hash_create (ctx->msgcount * 2, 1);
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;