Data Structures |
struct | EpkHashEntry |
| Data structure representing key/value pairs stored in the hash table. More...
|
Typedefs |
typedef struct EpkHashTab_struct | EpkHashTab |
| Opaque data structure representing a hash table.
|
typedef struct EpkHashIter_struct | EpkHashIter |
| Opaque data structure representing a hash table iterator.
|
typedef size_t(* | epk_ht_hash_f )(const void *key) |
| Pointer-to-function type describing hashing functions.
|
typedef int(* | epk_ht_kcmp_f )(const void *key, const void *item_key) |
| Pointer-to-function type describing key comparison functions.
|
typedef void(* | epk_ht_proc_f )(EpkHashEntry *entry) |
| Pointer-to-function type describing unary processing functions that can be used with epk_hashtab_foreach().
|
Functions |
|
EXTERN EpkHashTab * | epk_hashtab_create_size (size_t size, epk_ht_hash_f hashfunc, epk_ht_kcmp_f kcmpfunc) |
| Creates and returns an instance of EpkHashTab.
|
EXTERN void | epk_hashtab_free (EpkHashTab *instance) |
| Destroys the given instance of EpkHashTab and releases the allocated memory.
|
EXTERN size_t | epk_hashtab_size (const EpkHashTab *instance) |
| Returns the actual number of elements stored in the given EpkHashTab instance.
|
EXTERN int | epk_hashtab_empty (const EpkHashTab *instance) |
| Returns whether the given EpkHashTab instance is empty.
|
EXTERN void | epk_hashtab_insert (EpkHashTab *instance, void *key, void *value, size_t *index) |
| Inserts the given (key,value) pair into the EpkHashTab instance.
|
EXTERN EpkHashEntry * | epk_hashtab_find (const EpkHashTab *instance, const void *key, size_t *index) |
| Searches for the an hash table entry with the specified key in the given EpkHashTab instance, using the binary key comparison function cmpfunc (see epk_ht_kcmp_f for implementation details).
|
EXTERN void | epk_hashtab_foreach (const EpkHashTab *instance, epk_ht_proc_f procfunc) |
| Calls the unary processing function procfunc for each element of the given EpkHashTab instance.
|
|
EXTERN EpkHashIter * | epk_hashiter_create (const EpkHashTab *hashtab) |
| Creates and returns an iterator for the given EpkHashTab instance.
|
EXTERN void | epk_hashiter_free (EpkHashIter *instance) |
| Destroys the given instance of EpkHashIter and releases the allocated memory.
|
EXTERN EpkHashEntry * | epk_hashiter_first (EpkHashIter *instance) |
| Returns a pointer to the first entry of the hash table which is associated to the given iterator instance.
|
EXTERN EpkHashEntry * | epk_hashiter_next (EpkHashIter *instance) |
| Returns a pointer to the next entry of the hash table which is associated to the given iterator instance.
|
This file provides type definitions and function prototypes for a generic hash table data structure. The elements of such a hash table are stored in no particular order as a key/value pair, where both items are represented by void
pointers (see EpkHashEntry).
In addition, this module defines an associated iterator data type EpkHashIter, which allows convenient traversal of all entries stored in the hash table.
The epk_hashtab module follows an object-oriented style. That is, each function (except the two create functions) takes a pointer to an instance of either type EpkHashTab or EpkHashIter as their first argument, which is the object (i.e., the data structure) they operate on.
- Note:
- This module uses the
assert()
macro to check various conditions (especially the values of given parameters) at runtime, which can cause a performance penalty.
If a matching item could be found, a pointer to the key/value pair is returned. In addition, if index is non-NULL
, the hash table index is stored in the memory location pointed to by index, which can be used as an index hint for an subsequent call to epk_hashtab_insert(). Otherwise, i.e., if no matching item could be found, this function returns NULL
.
- Parameters:
-
instance | Object in which the item is searched |
key | Unique key to search for |
index | Memory location where index of matching item is stored (ignored if NULL ) |
- Returns:
- Pointer to hash table entry if matching item cound be found;
NULL
otherwise