37#define SOME_PRIME 149711
47 const unsigned char *s = (
const unsigned char *)
key.
strkey;
52 hash += ((hash << 7) + *s++);
74 const unsigned char *s = (
const unsigned char *)
key.
strkey;
79 hash += ((hash << 7) + tolower(*s++));
154 table->
table[hash] = he;
158 struct HashElem *tmp = NULL, *last = NULL;
160 for (tmp = table->
table[hash], last = NULL; tmp; last = tmp, tmp = tmp->
next)
174 table->
table[hash] = he;
193 for (; he; he = he->
next)
273 table->strdup_keys =
true;
275 table->allow_dups =
true;
291 table->allow_dups =
true;
305 table->hdata_free = fn;
306 table->hdata = fn_data;
318 const char *strkey,
int type,
void *
data)
320 if (!table || !strkey)
379 if (!table || !strkey)
411 if (!table || !strkey)
418 return table->
table[hash];
463 struct HashElem *he = NULL, *tmp = NULL;
465 for (
size_t i = 0; i < table->
num_elems; i++)
467 for (he = table->
table[i]; he;)
474 FREE(&tmp->key.strkey);
491 if (!table || !state)
static int cmp_key_case_string(union HashKey a, union HashKey b)
Compare two string keys (ignore case) - Implements hash_cmp_key_t -.
static int cmp_key_int(union HashKey a, union HashKey b)
Compare two integer keys - Implements hash_cmp_key_t -.
static int cmp_key_string(union HashKey a, union HashKey b)
Compare two string keys - Implements hash_cmp_key_t -.
static size_t gen_hash_string(union HashKey key, size_t num_elems)
Generate a hash from a string - Implements hash_gen_hash_t -.
static size_t gen_hash_case_string(union HashKey key, size_t num_elems)
Generate a hash from a string (ignore the case) - Implements hash_gen_hash_t -.
static size_t gen_hash_int(union HashKey key, size_t num_elems)
Generate a hash from an integer - Implements hash_gen_hash_t -.
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_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
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.
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
static void * union_hash_find(const struct HashTable *table, union HashKey key)
Find the HashElem data in a Hash Table element using a key.
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.
struct HashElem * mutt_hash_find_bucket(const struct HashTable *table, const char *strkey)
Find the HashElem 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)
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.
struct HashElem * mutt_hash_walk(const struct HashTable *table, struct HashWalkState *state)
Iterate through all the HashElem's in a Hash Table.
static struct HashTable * hash_new(size_t num_elems)
Create a new Hash Table.
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
struct HashElem * mutt_hash_find_elem(const struct HashTable *table, const char *strkey)
Find the HashElem in a Hash Table element using a 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.
void * mutt_hash_int_find(const struct HashTable *table, unsigned int intkey)
Find the HashElem data in a Hash Table element using a key.
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)
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
static void union_hash_delete(struct HashTable *table, union HashKey key, const void *data)
Remove an element from a Hash Table.
Hash Table data structure.
uint8_t HashFlags
Flags for mutt_hash_new(), e.g. MUTT_HASH_STRCASECMP.
#define MUTT_HASH_STRDUP_KEYS
make a copy of the keys
void(* hash_hdata_free_t)(int type, void *obj, intptr_t data)
#define MUTT_HASH_ALLOW_DUPS
allow duplicate keys to be inserted
#define MUTT_HASH_STRCASECMP
use strcasecmp() to compare keys
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Memory management wrappers.
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
char * mutt_str_dup(const char *str)
Copy a string, safely.
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
String manipulation functions.
The item stored in a Hash Table.
struct HashElem * next
Linked List.
union HashKey key
Key representing the data.
int type
Type of data stored in Hash Table, e.g. DT_STRING.
void * data
User-supplied data.
hash_gen_hash_t gen_hash
Function to generate hash id from the key.
struct HashElem ** table
Array of Hash keys.
hash_cmp_key_t cmp_key
Function to compare two Hash keys.
bool allow_dups
if set, duplicate keys are allowed
size_t num_elems
Number of buckets in the Hash Table.
bool strdup_keys
if set, the key->strkey is strdup()'d
intptr_t hdata
Data to pass to the hdata_free() function.
hash_hdata_free_t hdata_free
Function to free a Hash element.
Cursor to iterate through a Hash Table.
size_t index
Current position in table.
struct HashElem * last
Current element in linked list.
The data item stored in a HashElem.
const char * strkey
String key.
unsigned int intkey
Integer key.