55 #if !defined(__AMXC_HTABLE_H__)
56 #define __AMXC_HTABLE_H__
87 #define amxc_htable_it_get_data(it, type, member) \
88 ((type*) (((char*) it) - offsetof(type, member)))
102 #define amxc_htable_for_each(it, htable) \
103 for(amxc_htable_it_t* it = amxc_htable_get_first(htable), \
104 * it ## _next = amxc_htable_it_get_next(it); \
107 it ## _next = amxc_htable_it_get_next(it))
119 #define amxc_htable_iterate(it, htable) \
120 for(amxc_htable_it_t* it = amxc_htable_get_first(htable); \
122 it = amxc_htable_it_get_next(it))
129 #define AMXC_HTABLE_RANGE UINT32_MAX
297 const char*
const key);
375 const char*
const key,
402 const char*
const key);
673 return it != NULL ?
it->
key : NULL;
Ambiorix array API header file.
amxc_htable_it_t * amxc_htable_it_get_next(const amxc_htable_it_t *const reference)
Gets the next iterator in the hash table.
int amxc_htable_it_init(amxc_htable_it_t *const it)
Initializes a hash table.iterator.
void amxc_htable_it_clean(amxc_htable_it_t *const it, amxc_htable_it_delete_t func)
Removes the iterator from the htable and frees allocated memory.
amxc_htable_it_t * amxc_htable_it_get_next_key(const amxc_htable_it_t *const reference)
Gets the next iterator in the hash table with the same key.
void amxc_htable_it_take(amxc_htable_it_t *const it)
Removes the iterator from the hash table.
amxc_htable_it_t * amxc_htable_it_get_previous(const amxc_htable_it_t *const reference)
Gets the previous iterator in the hash table.
AMXC_INLINE const char * amxc_htable_it_get_key(const amxc_htable_it_t *const it)
Gets the key from the iterator.
amxc_htable_it_t * amxc_htable_it_get_previous_key(const amxc_htable_it_t *const reference)
Gets the previous iterator in the hash table with the same key.
int amxc_htable_init(amxc_htable_t *const htable, const size_t reserve)
Initializes a hash table.
void amxc_htable_delete(amxc_htable_t **htable, amxc_htable_it_delete_t func)
Frees the previously allocated hash table.
amxc_array_t * amxc_htable_get_sorted_keys(const amxc_htable_t *const htable)
Creates an array containing all keys of the hash table.
amxc_htable_it_t * amxc_htable_get_first(const amxc_htable_t *const htable)
Gets the first item stored in the table.
int amxc_htable_new(amxc_htable_t **htable, const size_t reserve)
Allocates a hash table.
AMXC_INLINE size_t amxc_htable_size(const amxc_htable_t *const htable)
Calculates the size of the hash table.
AMXC_INLINE bool amxc_htable_contains(const amxc_htable_t *const htable, const char *const key)
Verifies that a key is in the hash table.
AMXC_INLINE bool amxc_htable_is_empty(const amxc_htable_t *const htable)
Checks that the hash table is empty.
unsigned int(* amxc_htable_hash_func_t)(const char *key, const unsigned int len)
Definition of the hash function.
int amxc_htable_move(amxc_htable_t *const dest, amxc_htable_t *const src)
Moves all items from one hash table to another hash table.
unsigned int amxc_htable_key2index(const amxc_htable_t *const htable, const char *const key)
Converts a key into an index.
struct _amxc_htable amxc_htable_t
The hash table structure.
amxc_htable_it_t * amxc_htable_take(amxc_htable_t *const htable, const char *const key)
Removes a hash table iterator from the hash table.
void(* amxc_htable_it_delete_t)(const char *key, amxc_htable_it_t *it)
Definition of the hash table item delete function.
amxc_htable_it_t * amxc_htable_get_last(const amxc_htable_t *const htable)
Gets the last item stored in the table.
amxc_htable_it_t * amxc_htable_get(const amxc_htable_t *const htable, const char *const key)
Gets a hash table iterator from the hash table.
AMXC_INLINE size_t amxc_htable_capacity(const amxc_htable_t *const htable)
Calculates the capacity of the hash table.
AMXC_INLINE amxc_htable_it_t * amxc_htable_take_first(const amxc_htable_t *const htable)
Removes the first item stored in the table.
int amxc_htable_insert(amxc_htable_t *const htable, const char *const key, amxc_htable_it_t *const it)
Inserts an item in the hash table.
void amxc_htable_clean(amxc_htable_t *const htable, amxc_htable_it_delete_t func)
Removes all items from the hash table.
void amxc_htable_set_hash_func(amxc_htable_t *const htable, amxc_htable_hash_func_t func)
Sets the hash function for the hash table.
The array iterator structure.
The hash table iterator structure.
The hash table structure.
amxc_htable_hash_func_t hfunc
amxc_htable_it_delete_t it_del
static amxc_htable_it_t it[2000]
static amxc_htable_t * htable