Go to the documentation of this file.
37 #define SOME_PRIME 149711
45 const unsigned char *s = (
const unsigned char *)
key.
strkey;
48 hash += ((hash << 7) + *s++);
68 const unsigned char *s = (
const unsigned char *)
key.
strkey;
71 hash += ((hash << 7) + tolower(*s++));
146 table->
table[hash] = he;
150 struct HashElem *tmp = NULL, *last = NULL;
152 for (tmp = table->
table[hash], last = NULL; tmp; last = tmp, tmp = tmp->
next)
166 table->
table[hash] = he;
185 for (; he; he = he->
next)
265 table->strdup_keys =
true;
267 table->allow_dups =
true;
283 table->allow_dups =
true;
297 table->hdata_free = fn;
298 table->hdata = fn_data;
310 const char *strkey,
int type,
void *
data)
312 if (!table || !strkey)
371 if (!table || !strkey)
403 if (!table || !strkey)
410 return table->
table[hash];
453 struct HashElem *elem = NULL, *tmp = NULL;
455 for (
size_t i = 0; i < table->
num_elems; i++)
457 for (elem = table->
table[i]; elem;)
464 FREE(&tmp->key.strkey);
481 if (!table || !state)
static size_t gen_int_hash(union HashKey key, size_t num_elems)
Generate a hash from an integer - Implements hash_gen_hash_t.
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
void(* hash_hdata_free_t)(int type, void *obj, intptr_t data)
Prototype for Hash Destructor callback function.
unsigned int intkey
Integer key.
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
size_t num_elems
Number of elements in the Hash Table.
union HashKey key
Key representing the data.
uint8_t HashFlags
Flags for mutt_hash_new(), e.g. MUTT_HASH_STRCASECMP.
hash_gen_hash_t gen_hash
Function to generate hash id from the key.
void mutt_hash_set_destructor(struct HashTable *table, hash_hdata_free_t fn, intptr_t fn_data)
Set the destructor for a Hash Table.
bool strdup_keys
if set, the key->strkey is strdup()'d
void * data
User-supplied data.
struct HashElem * next
Linked List.
static struct HashTable * hash_new(size_t num_elems)
Create a new Hash Table.
static int cmp_int_key(union HashKey a, union HashKey b)
Compare two integer keys - Implements hash_cmp_key_t.
char * mutt_str_dup(const char *str)
Copy a string, safely.
struct HashElem ** table
Array of Hash keys.
static size_t gen_case_string_hash(union HashKey key, size_t num_elems)
Generate a hash from a string (ignore the case) - Implements hash_gen_hash_t.
void * mutt_hash_int_find(const struct HashTable *table, unsigned int intkey)
Find the HashElem data in a Hash Table element using a key.
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
bool allow_dups
if set, duplicate keys are allowed
intptr_t hdata
Data to pass to the hdata_free() function.
#define MUTT_HASH_ALLOW_DUPS
allow duplicate keys to be inserted
struct HashElem * mutt_hash_typed_insert(struct HashTable *table, const char *strkey, int type, void *data)
Insert a string with type info into a Hash Table.
const char * strkey
String key.
static size_t gen_string_hash(union HashKey key, size_t num_elems)
Generate a hash from a string - Implements hash_gen_hash_t.
The data item stored in a HashElem.
struct HashElem * mutt_hash_find_bucket(const struct HashTable *table, const char *strkey)
Find the HashElem in a Hash Table element using a key.
hash_hdata_free_t hdata_free
Function to free a Hash element.
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
void mutt_hash_int_delete(struct HashTable *table, unsigned int intkey, const void *data)
Remove an element from a Hash Table.
static struct HashElem * union_hash_insert(struct HashTable *table, union HashKey key, int type, void *data)
Insert into a hash table using a union as a key.
static int cmp_case_string_key(union HashKey a, union HashKey b)
Compare two string keys (ignore case) - Implements hash_cmp_key_t.
struct HashElem * mutt_hash_walk(const struct HashTable *table, struct HashWalkState *state)
Iterate through all the HashElem's in a Hash Table.
int type
Type of data stored in Hash Table, e.g. DT_STRING.
static struct HashElem * union_hash_find_elem(const struct HashTable *table, union HashKey key)
Find a HashElem in a Hash Table element using a key.
Cursor to iterate through a Hash Table.
size_t index
Current position in table.
hash_cmp_key_t cmp_key
Function to compare two Hash keys.
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
The item stored in a Hash Table.
#define MUTT_HASH_STRCASECMP
use strcasecmp() to compare keys
struct HashElem * mutt_hash_int_insert(struct HashTable *table, unsigned int intkey, void *data)
Add a new element to the Hash Table (with integer keys)
#define MUTT_HASH_STRDUP_KEYS
make a copy of the keys
static void * union_hash_find(const struct HashTable *table, union HashKey key)
Find the HashElem data in a Hash Table element using a key.
struct HashTable * mutt_hash_int_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with integer keys)
static int cmp_string_key(union HashKey a, union HashKey b)
Compare two string keys - Implements hash_cmp_key_t.
static void union_hash_delete(struct HashTable *table, union HashKey key, const void *data)
Remove an element from a Hash Table.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
struct HashElem * mutt_hash_find_elem(const struct HashTable *table, const char *strkey)
Find the HashElem in a Hash Table element using a key.
struct HashElem * last
Current element in linked list.