Hash tables templates. More...
Go to the source code of this file.
Defines | |
#define | HTABLE_H |
Defined when <sofia-sip/htable.h> has been included. | |
#define | HTABLE_MIN_SIZE |
Minimum size of hash table. | |
#define | HTABLE_DECLARE(prefix, pr, entry_t) |
Declare hash table structure type. | |
#define | HTABLE_SCOPE |
Default scope for hash table functions. | |
#define | HTABLE_PROTOS(prefix, pr, entry_t) |
Prototypes for hash table. | |
#define | HTABLE_BODIES(prefix, pr, entry_t, hfun) |
Hash table implementation. |
Hash tables templates.
This file contain a hash table template for C. The hash tables are resizeable, and they usually contain pointers to entries. The declaration for template datatypes is instantiated with macro HTABLE_DECLARE(). The prototypes for hashing functions are instantiated with macro HTABLE_PROTOS(). The implementation is instantiated with macro HTABLE_BODIES().
The hash table template is most efficient when the hash value is precalculated and stored in each entry. The hash "function" given to the HTABLE_BODIES() would then be something like macro
#define HTABLE_ENTRY_HASH(e) ((e)->e_hash_value)
When a entry with new identical hash key is added to the table, it can be either inserted (before any other entry with same key value) or appended.
Example code can be found from <htable_test.c>.
#define HTABLE_BODIES | ( | prefix, | ||
pr, | ||||
entry_t, | ||||
hfun | ||||
) |
Hash table implementation.
The macro HTABLE_BODIES() expands the hash table functions. The function and type names start with prefix, the field names start with pr. The entry type is entry_t. The function (or macro) name returning hash value of each entry is given as hfun.
prefix | hash table type and function prefix | |
pr | hash table field prefix | |
entry_t | entry type | |
hfun | function or macro returning hash value of entry |
#define HTABLE_DECLARE | ( | prefix, | ||
pr, | ||||
entry_t | ||||
) |
Declare hash table structure type.
The macro HTABLE_DECLARE() expands to a declaration for hash table structure. The its typedef will be prefix_t
, the field names start withb pr. The entry type is entry_t.
prefix | hash table type and function prefix | |
pr | hash table field prefix | |
entry_t | entry type |
#define HTABLE_H |
Defined when <sofia-sip/htable.h> has been included.
#define HTABLE_PROTOS | ( | prefix, | ||
pr, | ||||
entry_t | ||||
) |
Prototypes for hash table.
The macro HTABLE_PROTOS() expands to the prototypes of hash table functions. The function and type names start with prefix, the field names start with pr. The entry type is entry_t.
prefix | hash table type and function prefix | |
pr | hash table field prefix | |
entry_t | entry type |
#define HTABLE_SCOPE |
Default scope for hash table functions.