Mercury
|
Hash table. More...
#include "mercury_util_config.h"
Go to the source code of this file.
Classes | |
struct | hg_hash_table_iter |
Definition of a hg_hash_table_iter. More... | |
Macros | |
#define | HG_HASH_TABLE_NULL ((void *) 0) |
A null HashTableValue. More... | |
Typedefs | |
typedef struct hg_hash_table | hg_hash_table_t |
A hash table structure. More... | |
typedef struct hg_hash_table_iter | hg_hash_table_iter_t |
Structure used to iterate over a hash table. More... | |
typedef struct hg_hash_table_entry | hg_hash_table_entry_t |
Internal structure representing an entry in a hash table. More... | |
typedef void * | hg_hash_table_key_t |
A key to look up a value in a hg_hash_table_t. More... | |
typedef void * | hg_hash_table_value_t |
A value stored in a hg_hash_table_t. More... | |
typedef unsigned int(* | hg_hash_table_hash_func_t )(hg_hash_table_key_t value) |
Hash function used to generate hash values for keys used in a hash table. More... | |
typedef int(* | hg_hash_table_equal_func_t )(hg_hash_table_key_t value1, hg_hash_table_key_t value2) |
Function used to compare two keys for equality. More... | |
typedef void(* | hg_hash_table_key_free_func_t )(hg_hash_table_key_t value) |
Type of function used to free keys when entries are removed from a hash table. More... | |
typedef void(* | hg_hash_table_value_free_func_t )(hg_hash_table_value_t value) |
Type of function used to free values when entries are removed from a hash table. More... | |
Functions | |
HG_UTIL_EXPORT hg_hash_table_t * | hg_hash_table_new (hg_hash_table_hash_func_t hash_func, hg_hash_table_equal_func_t equal_func) |
Create a new hash table. More... | |
HG_UTIL_EXPORT void | hg_hash_table_free (hg_hash_table_t *hash_table) |
Destroy a hash table. More... | |
HG_UTIL_EXPORT void | hg_hash_table_register_free_functions (hg_hash_table_t *hash_table, hg_hash_table_key_free_func_t key_free_func, hg_hash_table_value_free_func_t value_free_func) |
Register functions used to free the key and value when an entry is removed from a hash table. More... | |
HG_UTIL_EXPORT int | hg_hash_table_insert (hg_hash_table_t *hash_table, hg_hash_table_key_t key, hg_hash_table_value_t value) |
Insert a value into a hash table, overwriting any existing entry using the same key. More... | |
HG_UTIL_EXPORT hg_hash_table_value_t | hg_hash_table_lookup (hg_hash_table_t *hash_table, hg_hash_table_key_t key) |
Look up a value in a hash table by key. More... | |
HG_UTIL_EXPORT int | hg_hash_table_remove (hg_hash_table_t *hash_table, hg_hash_table_key_t key) |
Remove a value from a hash table. More... | |
HG_UTIL_EXPORT unsigned int | hg_hash_table_num_entries (hg_hash_table_t *hash_table) |
Retrieve the number of entries in a hash table. More... | |
HG_UTIL_EXPORT void | hg_hash_table_iterate (hg_hash_table_t *hash_table, hg_hash_table_iter_t *iter) |
Initialise a HashTableIterator to iterate over a hash table. More... | |
HG_UTIL_EXPORT int | hg_hash_table_iter_has_more (hg_hash_table_iter_t *iterator) |
Determine if there are more keys in the hash table to iterate over. More... | |
HG_UTIL_EXPORT hg_hash_table_value_t | hg_hash_table_iter_next (hg_hash_table_iter_t *iterator) |
Using a hash table iterator, retrieve the next key. More... | |
Hash table.
A hash table stores a set of values which can be addressed by a key. Given the key, the corresponding value can be looked up quickly.
To create a hash table, use hg_hash_table_new. To destroy a hash table, use hg_hash_table_free.
To insert a value into a hash table, use hg_hash_table_insert.
To remove a value from a hash table, use hg_hash_table_remove.
To look up a value by its key, use hg_hash_table_lookup.
To iterate over all values in a hash table, use hg_hash_table_iterate to initialize a hg_hash_table_iter structure. Each value can then be read in turn using hg_hash_table_iter_next and hg_hash_table_iter_has_more.
Definition in file mercury_hash_table.h.
#define HG_HASH_TABLE_NULL ((void *) 0) |
A null HashTableValue.
Definition at line 99 of file mercury_hash_table.h.
typedef struct hg_hash_table hg_hash_table_t |
A hash table structure.
Definition at line 59 of file mercury_hash_table.h.
typedef struct hg_hash_table_iter hg_hash_table_iter_t |
Structure used to iterate over a hash table.
Definition at line 65 of file mercury_hash_table.h.
typedef struct hg_hash_table_entry hg_hash_table_entry_t |
Internal structure representing an entry in a hash table.
Definition at line 71 of file mercury_hash_table.h.
typedef void* hg_hash_table_key_t |
A key to look up a value in a hg_hash_table_t.
Definition at line 77 of file mercury_hash_table.h.
typedef void* hg_hash_table_value_t |
A value stored in a hg_hash_table_t.
Definition at line 83 of file mercury_hash_table.h.
typedef unsigned int(* hg_hash_table_hash_func_t)(hg_hash_table_key_t value) |
Hash function used to generate hash values for keys used in a hash table.
value | The value to generate a hash value for. |
Definition at line 109 of file mercury_hash_table.h.
typedef int(* hg_hash_table_equal_func_t)(hg_hash_table_key_t value1, hg_hash_table_key_t value2) |
Function used to compare two keys for equality.
Definition at line 118 of file mercury_hash_table.h.
typedef void(* hg_hash_table_key_free_func_t)(hg_hash_table_key_t value) |
Type of function used to free keys when entries are removed from a hash table.
Definition at line 125 of file mercury_hash_table.h.
typedef void(* hg_hash_table_value_free_func_t)(hg_hash_table_value_t value) |
Type of function used to free values when entries are removed from a hash table.
Definition at line 132 of file mercury_hash_table.h.
HG_UTIL_EXPORT hg_hash_table_t* hg_hash_table_new | ( | hg_hash_table_hash_func_t | hash_func, |
hg_hash_table_equal_func_t | equal_func | ||
) |
Create a new hash table.
hash_func | Function used to generate hash keys for the keys used in the table. |
equal_func | Function used to test keys used in the table for equality. |
HG_UTIL_EXPORT void hg_hash_table_free | ( | hg_hash_table_t * | hash_table | ) |
Destroy a hash table.
hash_table | The hash table to destroy. |
HG_UTIL_EXPORT void hg_hash_table_register_free_functions | ( | hg_hash_table_t * | hash_table, |
hg_hash_table_key_free_func_t | key_free_func, | ||
hg_hash_table_value_free_func_t | value_free_func | ||
) |
Register functions used to free the key and value when an entry is removed from a hash table.
hash_table | The hash table. |
key_free_func | Function used to free keys. |
value_free_func | Function used to free values. |
HG_UTIL_EXPORT int hg_hash_table_insert | ( | hg_hash_table_t * | hash_table, |
hg_hash_table_key_t | key, | ||
hg_hash_table_value_t | value | ||
) |
Insert a value into a hash table, overwriting any existing entry using the same key.
hash_table | The hash table. |
key | The key for the new value. |
value | The value to insert. |
HG_UTIL_EXPORT hg_hash_table_value_t hg_hash_table_lookup | ( | hg_hash_table_t * | hash_table, |
hg_hash_table_key_t | key | ||
) |
Look up a value in a hash table by key.
hash_table | The hash table. |
key | The key of the value to look up. |
HG_UTIL_EXPORT int hg_hash_table_remove | ( | hg_hash_table_t * | hash_table, |
hg_hash_table_key_t | key | ||
) |
Remove a value from a hash table.
hash_table | The hash table. |
key | The key of the value to remove. |
HG_UTIL_EXPORT unsigned int hg_hash_table_num_entries | ( | hg_hash_table_t * | hash_table | ) |
Retrieve the number of entries in a hash table.
hash_table | The hash table. |
HG_UTIL_EXPORT void hg_hash_table_iterate | ( | hg_hash_table_t * | hash_table, |
hg_hash_table_iter_t * | iter | ||
) |
Initialise a HashTableIterator to iterate over a hash table.
hash_table | The hash table. |
iter | Pointer to an iterator structure to initialise. |
HG_UTIL_EXPORT int hg_hash_table_iter_has_more | ( | hg_hash_table_iter_t * | iterator | ) |
Determine if there are more keys in the hash table to iterate over.
iterator | The hash table iterator. |
HG_UTIL_EXPORT hg_hash_table_value_t hg_hash_table_iter_next | ( | hg_hash_table_iter_t * | iterator | ) |
Using a hash table iterator, retrieve the next key.
iterator | The hash table iterator. |