Go to the source code of this file.
Classes | |
struct | lh_entry |
struct | lh_table |
Macros | |
#define | LH_EMPTY (void*)-1 |
#define | lh_foreach(table, entry) for(entry = table->head; entry; entry = entry->next) |
#define | lh_foreach_safe(table, entry, tmp) for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp) |
#define | LH_FREED (void*)-2 |
#define | LH_PRIME 0x9e370001UL |
Typedefs | |
typedef void( | lh_entry_free_fn) (struct lh_entry *e) |
typedef int( | lh_equal_fn) (void *k1, void *k2) |
typedef unsigned long( | lh_hash_fn) (void *k) |
Functions | |
int | lh_char_equal (void *k1, void *k2) |
unsigned long | lh_char_hash (void *k) |
struct lh_table * | lh_kchar_table_new (int size, char *name, lh_entry_free_fn *free_fn) |
struct lh_table * | lh_kptr_table_new (int size, char *name, lh_entry_free_fn *free_fn) |
int | lh_ptr_equal (void *k1, void *k2) |
unsigned long | lh_ptr_hash (void *k) |
int | lh_table_delete (struct lh_table *t, void *k) |
int | lh_table_delete_entry (struct lh_table *t, struct lh_entry *e) |
void | lh_table_free (struct lh_table *t) |
int | lh_table_insert (struct lh_table *t, void *k, void *v) |
void * | lh_table_lookup (struct lh_table *t, void *k) |
struct lh_entry * | lh_table_lookup_entry (struct lh_table *t, void *k) |
struct lh_table * | lh_table_new (int size, char *name, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn, lh_equal_fn *equal_fn) |
#define LH_EMPTY (void*)-1 |
sentinel pointer value for empty slots
Definition at line 23 of file linkhash.h.
#define lh_foreach | ( | table, | |
entry | |||
) | for(entry = table->head; entry; entry = entry->next) |
Convenience list iterator.
Definition at line 145 of file linkhash.h.
#define lh_foreach_safe | ( | table, | |
entry, | |||
tmp | |||
) | for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp) |
lh_foreach_safe allows calling of deletion routine while iterating.
Definition at line 151 of file linkhash.h.
#define LH_FREED (void*)-2 |
sentinel pointer value for freed slots
Definition at line 28 of file linkhash.h.
#define LH_PRIME 0x9e370001UL |
golden prime used in hash functions
Definition at line 18 of file linkhash.h.
typedef void( lh_entry_free_fn) (struct lh_entry *e) |
callback function prototypes
Definition at line 35 of file linkhash.h.
typedef int( lh_equal_fn) (void *k1, void *k2) |
callback function prototypes
Definition at line 43 of file linkhash.h.
typedef unsigned long( lh_hash_fn) (void *k) |
callback function prototypes
Definition at line 39 of file linkhash.h.
int lh_char_equal | ( | void * | k1, |
void * | k2 | ||
) |
Definition at line 52 of file linkhash.c.
unsigned long lh_char_hash | ( | void * | k | ) |
Definition at line 42 of file linkhash.c.
struct lh_table* lh_kchar_table_new | ( | int | size, |
char * | name, | ||
lh_entry_free_fn * | free_fn | ||
) |
Convenience function to create a new linkhash table with char keys.
size | initial table size. |
name | table name. |
free_fn | callback function used to free memory for entries. |
Definition at line 79 of file linkhash.c.
struct lh_table* lh_kptr_table_new | ( | int | size, |
char * | name, | ||
lh_entry_free_fn * | free_fn | ||
) |
Convenience function to create a new linkhash table with ptr keys.
size | initial table size. |
name | table name. |
free_fn | callback function used to free memory for entries. |
Definition at line 85 of file linkhash.c.
int lh_ptr_equal | ( | void * | k1, |
void * | k2 | ||
) |
Definition at line 37 of file linkhash.c.
unsigned long lh_ptr_hash | ( | void * | k | ) |
Pre-defined hash and equality functions
Definition at line 31 of file linkhash.c.
int lh_table_delete | ( | struct lh_table * | t, |
void * | k | ||
) |
Delete a record from the table. If a callback free function is provided then it is called for the for the item being deleted.
t | the table to delete from. |
k | a pointer to the key to delete. |
Definition at line 211 of file linkhash.c.
Delete a record from the table. If a callback free function is provided then it is called for the for the item being deleted.
t | the table to delete from. |
e | a pointer to the entry to delete. |
Definition at line 182 of file linkhash.c.
void lh_table_free | ( | struct lh_table * | t | ) |
Free a linkhash table. If a callback free function is provided then it is called for all entries in the table.
t | table to free. |
Definition at line 111 of file linkhash.c.
int lh_table_insert | ( | struct lh_table * | t, |
void * | k, | ||
void * | v | ||
) |
Insert a record into the table.
t | the table to insert into. |
k | a pointer to the key to insert. |
v | a pointer to the value to insert. |
Definition at line 124 of file linkhash.c.
void* lh_table_lookup | ( | struct lh_table * | t, |
void * | k | ||
) |
Lookup a record into the table
t | the table to lookup |
k | a pointer to the key to lookup |
Definition at line 174 of file linkhash.c.
Lookup a record into the table.
t | the table to lookup |
k | a pointer to the key to lookup |
Definition at line 158 of file linkhash.c.
struct lh_table* lh_table_new | ( | int | size, |
char * | name, | ||
lh_entry_free_fn * | free_fn, | ||
lh_hash_fn * | hash_fn, | ||
lh_equal_fn * | equal_fn | ||
) |
Create a new linkhash table.
size | initial table size. The table is automatically resized although this incurs a performance penalty. |
name | the table name. |
free_fn | callback function used to free memory for entries when lh_table_free or lh_table_delete is called. If NULL is provided, then memory for keys and values must be freed by the caller. |
hash_fn | function used to hash keys. 2 standard ones are defined: lh_ptr_hash and lh_char_hash for hashing pointer values and C strings respectively. |
equal_fn | comparison function to compare keys. 2 standard ones defined: lh_ptr_hash and lh_char_hash for comparing pointer values and C strings respectively. |
Definition at line 57 of file linkhash.c.