Hash Table data structure. More...
#include "config.h"
#include <ctype.h>
#include <stdbool.h>
#include "hash.h"
#include "memory.h"
#include "string2.h"
Go to the source code of this file.
Macros | |
#define | SOME_PRIME 149711 |
Functions | |
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 int | cmp_key_string (union HashKey a, union HashKey b) |
Compare two string keys - Implements hash_cmp_key_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 int | cmp_key_case_string (union HashKey a, union HashKey b) |
Compare two string keys (ignore case) - Implements hash_cmp_key_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 -. | |
static int | cmp_key_int (union HashKey a, union HashKey b) |
Compare two integer keys - Implements hash_cmp_key_t -. | |
static struct HashTable * | hash_new (size_t num_elems) |
Create a new 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 struct HashElem * | union_hash_find_elem (const struct HashTable *table, union HashKey key) |
Find a HashElem 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. | |
static void | union_hash_delete (struct HashTable *table, union HashKey key, const void *data) |
Remove an element from a Hash Table. | |
struct HashTable * | mutt_hash_new (size_t num_elems, HashFlags flags) |
Create a new Hash Table (with string keys) | |
struct HashTable * | mutt_hash_int_new (size_t num_elems, HashFlags flags) |
Create a new Hash Table (with integer keys) | |
void | mutt_hash_set_destructor (struct HashTable *table, hash_hdata_free_t fn, intptr_t fn_data) |
Set the destructor for a Hash Table. | |
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_insert (struct HashTable *table, const char *strkey, void *data) |
Add a new element to the Hash Table (with string 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) | |
void * | mutt_hash_find (const struct HashTable *table, const char *strkey) |
Find the HashElem data in a Hash Table element using a key. | |
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_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_find_bucket (const struct HashTable *table, const char *strkey) |
Find the HashElem in a Hash Table element using a key. | |
void | mutt_hash_delete (struct HashTable *table, const char *strkey, const void *data) |
Remove an element from a Hash Table. | |
void | mutt_hash_int_delete (struct HashTable *table, unsigned int intkey, 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_walk (const struct HashTable *table, struct HashWalkState *state) |
Iterate through all the HashElem's in a Hash Table. | |
Hash Table data structure.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file hash.c.
|
static |
Create a new Hash Table.
num_elems | Number of elements it should contain |
ptr | New Hash Table |
The Hash Table can contain more elements than num_elems, but they will be chained together.
Definition at line 121 of file hash.c.
|
static |
Insert into a hash table using a union as a key.
table | Hash Table to update |
key | Key to hash on |
type | Data type |
data | Data to associate with key |
ptr | Newly inserted HashElem |
Definition at line 139 of file hash.c.
|
static |
Find a HashElem in a Hash Table element using a key.
table | Hash Table to search |
key | Key (either string or integer) |
ptr | HashElem matching the key |
Definition at line 186 of file hash.c.
Find the HashElem data in a Hash Table element using a key.
table | Hash Table to search |
key | Key (either string or integer) |
ptr | Data attached to the HashElem matching the key |
Definition at line 207 of file hash.c.
|
static |
Remove an element from a Hash Table.
table | Hash Table to use |
key | Key (either string or integer) |
data | Private data to match (or NULL for any match) |
Definition at line 223 of file hash.c.
Create a new Hash Table (with string keys)
num_elems | Number of elements it should contain |
flags | Flags, see HashFlags |
ptr | New Hash Table |
Definition at line 259 of file hash.c.
Create a new Hash Table (with integer keys)
num_elems | Number of elements it should contain |
flags | Flags, see HashFlags |
ptr | New Hash Table |
Definition at line 285 of file hash.c.
void mutt_hash_set_destructor | ( | struct HashTable * | table, |
hash_hdata_free_t | fn, | ||
intptr_t | fn_data | ||
) |
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.
table | Hash Table to use |
strkey | String key |
type | Type to associate with the key |
data | Private data associated with the key |
ptr | Newly inserted HashElem |
Definition at line 317 of file hash.c.
Add a new element to the Hash Table (with string keys)
table | Hash Table (with string keys) |
strkey | String key |
data | Private data associated with the key |
ptr | Newly inserted HashElem |
Definition at line 335 of file hash.c.
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)
table | Hash Table (with integer keys) |
intkey | Integer key |
data | Private data associated with the key |
ptr | Newly inserted HashElem |
Definition at line 347 of file hash.c.
void * mutt_hash_find | ( | const struct HashTable * | table, |
const char * | strkey | ||
) |
Find the HashElem data in a Hash Table element using a key.
table | Hash Table to search |
strkey | String key to search for |
ptr | Data attached to the HashElem matching the key |
Definition at line 362 of file hash.c.
Find the HashElem in a Hash Table element using a key.
table | Hash Table to search |
strkey | String key to search for |
ptr | HashElem matching the key |
Definition at line 377 of file hash.c.
void * mutt_hash_int_find | ( | const struct HashTable * | table, |
unsigned int | intkey | ||
) |
Find the HashElem data in a Hash Table element using a key.
table | Hash Table to search |
intkey | Integer key |
ptr | Data attached to the HashElem matching the key |
Definition at line 392 of file hash.c.
Find the HashElem in a Hash Table element using a key.
table | Hash Table to search |
strkey | String key to search for |
ptr | HashElem matching the key |
Unlike mutt_hash_find_elem(), this will return the first matching entry.
Definition at line 409 of file hash.c.
void mutt_hash_delete | ( | struct HashTable * | table, |
const char * | strkey, | ||
const void * | data | ||
) |
Remove an element from a Hash Table.
table | Hash Table to use |
strkey | String key to match |
data | Private data to match (or NULL for any match) |
Definition at line 427 of file hash.c.
void mutt_hash_int_delete | ( | struct HashTable * | table, |
unsigned int | intkey, | ||
const void * | data | ||
) |
Remove an element from a Hash Table.
table | Hash Table to use |
intkey | Integer key to match |
data | Private data to match (or NULL for any match) |
Definition at line 444 of file hash.c.
void mutt_hash_free | ( | struct HashTable ** | ptr | ) |
Free a hash table.
[out] | ptr | Hash Table to be freed |
Definition at line 457 of file hash.c.
struct HashElem * mutt_hash_walk | ( | const struct HashTable * | table, |
struct HashWalkState * | state | ||
) |
Iterate through all the HashElem's in a Hash Table.
table | Hash Table to search |
state | Cursor to keep track |
Definition at line 489 of file hash.c.