};
/**
- * destroy - Callback function for the Hash Table - Implements ::hash_destructor_t
+ * destroy - Callback function for the Hash Table - Implements ::hashelem_free_t
* @param type Object type, e.g. #DT_STRING
* @param obj Object to destroy
* @param data ConfigSet associated with the object
if (!cs || !*cs)
return; /* LCOV_EXCL_LINE */
- mutt_hash_destroy(&(*cs)->hash);
+ mutt_hash_free(&(*cs)->hash);
FREE(cs);
}
}
/**
- * thread_hash_destructor - Hash Destructor callback - Implements ::hash_destructor_t
+ * thread_hash_destructor - Hash Destructor callback - Implements ::hashelem_free_t
*/
void thread_hash_destructor(int type, void *obj, intptr_t data)
{
*/
void imap_mdata_cache_reset(struct ImapMboxData *mdata)
{
- mutt_hash_destroy(&mdata->uid_hash);
+ mutt_hash_free(&mdata->uid_hash);
FREE(&mdata->msn_index);
mdata->msn_index_size = 0;
mdata->max_msn = 0;
mutt_regexlist_free(&UnSubscribedLists);
mutt_grouplist_free();
- mutt_hash_destroy(&ReverseAliases);
- mutt_hash_destroy(&TagFormats);
- mutt_hash_destroy(&TagTransforms);
+ mutt_hash_free(&ReverseAliases);
+ mutt_hash_free(&TagFormats);
+ mutt_hash_free(&TagTransforms);
/* Lists of strings */
mutt_list_free(&AlternativeOrderList);
}
/* destroy the file name hash */
- mutt_hash_destroy(&fnames);
+ mutt_hash_free(&fnames);
/* If we didn't just get new mail, update the tables. */
if (occult)
/* destroy the file name hash */
- mutt_hash_destroy(&fnames);
+ mutt_hash_free(&fnames);
/* If we didn't just get new mail, update the tables. */
if (occult)
old_msgcount = 0;
/* simulate a close */
- mutt_hash_destroy(&m->id_hash);
- mutt_hash_destroy(&m->subj_hash);
- mutt_hash_destroy(&m->label_hash);
+ mutt_hash_free(&m->id_hash);
+ mutt_hash_free(&m->subj_hash);
+ mutt_hash_free(&m->label_hash);
mutt_clear_threads(ctx);
FREE(&m->v2r);
if (m->readonly)
*/
void mutt_grouplist_free(void)
{
- mutt_hash_destroy(&Groups);
+ mutt_hash_free(&Groups);
}
/**
if ((data == ptr->data || !data) && table->cmp_key(ptr->key, key) == 0)
{
*last = ptr->next;
- if (table->destroy)
- table->destroy(ptr->type, ptr->data, table->dest_data);
+ if (table->elem_free)
+ table->elem_free(ptr->type, ptr->data, table->hash_data);
if (table->strdup_keys)
FREE(&ptr->key.strkey);
FREE(&ptr);
* @param fn Callback function to free Hash Table's resources
* @param fn_data Data to pass to the callback function
*/
-void mutt_hash_set_destructor(struct Hash *table, hash_destructor_t fn, intptr_t fn_data)
+void mutt_hash_set_destructor(struct Hash *table, hashelem_free_t fn, intptr_t fn_data)
{
- table->destroy = fn;
- table->dest_data = fn_data;
+ table->elem_free = fn;
+ table->hash_data = fn_data;
}
/**
}
/**
- * mutt_hash_destroy - Destroy a hash table
+ * mutt_hash_free - elem_free a hash table
* @param ptr Hash Table to be freed
*/
-void mutt_hash_destroy(struct Hash **ptr)
+void mutt_hash_free(struct Hash **ptr)
{
struct Hash *pptr = NULL;
struct HashElem *elem = NULL, *tmp = NULL;
{
tmp = elem;
elem = elem->next;
- if (pptr->destroy)
- pptr->destroy(tmp->type, tmp->data, pptr->dest_data);
+ if (pptr->elem_free)
+ pptr->elem_free(tmp->type, tmp->data, pptr->hash_data);
if (pptr->strdup_keys)
FREE(&tmp->key.strkey);
FREE(&tmp);
};
/**
- * typedef hash_destructor_t - Prototype for Hash Destructor callback function
+ * typedef hashelem_free_t - Prototype for Hash Destructor callback function
* @param type Hash Type
* @param obj Object to free
* @param data Data associated with the Hash
*/
-typedef void (*hash_destructor_t)(int type, void *obj, intptr_t data);
+typedef void (*hashelem_free_t)(int type, void *obj, intptr_t data);
/**
* struct Hash - A Hash Table
*/
struct Hash
{
- size_t nelem;
- bool strdup_keys : 1; /**< if set, the key->strkey is strdup'ed */
- bool allow_dups : 1; /**< if set, duplicate keys are allowed */
- struct HashElem **table;
- size_t (*gen_hash)(union HashKey, size_t);
- int (*cmp_key)(union HashKey, union HashKey);
- hash_destructor_t destroy;
- intptr_t dest_data;
+ size_t nelem; ///< Number of elements in the Hash table
+ bool strdup_keys : 1; ///< if set, the key->strkey is strdup'ed
+ bool allow_dups : 1; ///< if set, duplicate keys are allowed
+ struct HashElem **table; ///< Array of Hash keys
+ size_t (*gen_hash)(union HashKey, size_t); ///< Function to generate hash id from the key
+ int (*cmp_key)(union HashKey, union HashKey); ///< Function to compare two Hash keys
+ hashelem_free_t elem_free; ///< Function to free a Hash element
+ intptr_t hash_data; ///< Data to pass to the elem_free() function
};
/* flags for mutt_hash_new() */
#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 */
-struct Hash * mutt_hash_new(size_t nelem, int flags);
void mutt_hash_delete(struct Hash *table, const char *strkey, const void *data);
-void mutt_hash_destroy(struct Hash **ptr);
-void * mutt_hash_find(const struct Hash *table, const char *strkey);
struct HashElem *mutt_hash_find_bucket(const struct Hash *table, const char *strkey);
+void * mutt_hash_find(const struct Hash *table, const char *strkey);
struct HashElem *mutt_hash_find_elem(const struct Hash *table, const char *strkey);
+void mutt_hash_free(struct Hash **ptr);
struct HashElem *mutt_hash_insert(struct Hash *table, const char *strkey, void *data);
-struct Hash * mutt_hash_int_new(size_t nelem, int flags);
void mutt_hash_int_delete(struct Hash *table, unsigned int intkey, const void *data);
void * mutt_hash_int_find(const struct Hash *table, unsigned int intkey);
struct HashElem *mutt_hash_int_insert(struct Hash *table, unsigned int intkey, void *data);
-void mutt_hash_set_destructor(struct Hash *table, hash_destructor_t fn, intptr_t fn_data);
+struct Hash * mutt_hash_int_new(size_t nelem, int flags);
+struct Hash * mutt_hash_new(size_t nelem, int flags);
+void mutt_hash_set_destructor(struct Hash *table, hashelem_free_t fn, intptr_t fn_data);
struct HashElem *mutt_hash_typed_insert(struct Hash *table, const char *strkey, int type, void *data);
/**
}
if (HistoryRemoveDups)
for (hclass = 0; hclass < HC_MAX; hclass++)
- mutt_hash_destroy(&dup_hashes[hclass]);
+ mutt_hash_free(&dup_hashes[hclass]);
}
/**
ctx->tree = NULL;
if (ctx->thread_hash)
- mutt_hash_destroy(&ctx->thread_hash);
+ mutt_hash_free(&ctx->thread_hash);
}
/**
if (m->mx_ops)
m->mx_ops->mbox_close(m);
- mutt_hash_destroy(&m->subj_hash);
- mutt_hash_destroy(&m->id_hash);
- mutt_hash_destroy(&m->label_hash);
+ mutt_hash_free(&m->subj_hash);
+ mutt_hash_free(&m->id_hash);
+ mutt_hash_free(&m->label_hash);
if (m->emails)
{
mutt_clear_threads(ctx);
if (m->subj_hash)
{
- mutt_hash_destroy(&m->subj_hash);
+ mutt_hash_free(&m->subj_hash);
}
m->subj_hash = NULL;
if (m->id_hash)
{
- mutt_hash_destroy(&m->id_hash);
+ mutt_hash_free(&m->id_hash);
}
m->id_hash = NULL;
}
}
-/**
- * nntp_hash_destructor_t - Free our hash table data - Implements ::hash_destructor_t
- */
-void nntp_hash_destructor_t(int type, void *obj, intptr_t data)
-{
- nntp_mdata_free(&obj);
-}
-
/**
* nntp_newsrc_close - Unlock and close .newsrc file
* @param adata NNTP server
if (rc < 0)
{
- mutt_hash_destroy(&adata->groups_hash);
+ mutt_hash_free(&adata->groups_hash);
FREE(&adata->groups_list);
FREE(&adata->newsrc_file);
FREE(&adata->authenticators);
FREE(ptr);
}
+/**
+ * nntp_hashelem_free - Free our hash table data - Implements ::hashelem_free_t
+ */
+void nntp_hashelem_free(int type, void *obj, intptr_t data)
+{
+ nntp_mdata_free(&obj);
+}
+
/**
* nntp_adata_new - Allocate and initialise a new NntpAccountData structure
* @retval ptr New NntpAccountData
struct NntpAccountData *adata = mutt_mem_calloc(1, sizeof(struct NntpAccountData));
adata->conn = conn;
adata->groups_hash = mutt_hash_new(1009, 0);
- mutt_hash_set_destructor(adata->groups_hash, nntp_hash_destructor_t, 0);
+ mutt_hash_set_destructor(adata->groups_hash, nntp_hashelem_free, 0);
adata->groups_max = 16;
adata->groups_list =
mutt_mem_malloc(adata->groups_max * sizeof(struct NntpMboxData *));