a simple hash table implementation More...
#include <sys/types.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | hash_table_element |
stores an hash table element for use in the hash table More... | |
struct | hash_table |
identifies the hashtable for which operations are to be performed More... | |
Macros | |
#define | HASH_LEN table->key_num |
#define | HASH(x, y) hash_table_do_hash(x,y,HASH_LEN) |
#define | hash_table_element_s sizeof(hash_table_element_t) |
#define | hash_table_s sizeof(hash_table_t) |
#define | HT_ADD(table, key, value) hash_table_add(table, (void *) key, sizeof(*key), (void *) value, sizeof(*value)) |
#define | HT_REMOVE(table, key) hash_table_remove(table, key, sizeof(*key)) |
#define | HT_LOOKUP(table, key) hash_table_lookup(table, key, sizeof(*key)) |
#define | HT_HAS_KEY(table, key) hash_table_has_key(table, key, sizeof(*key)) |
Typedefs | |
typedef struct hash_table_element | hash_table_element_t |
typedef enum hash_table_mode | hash_table_mode_t |
typedef struct hash_table | hash_table_t |
Enumerations | |
enum | hash_table_mode { MODE_COPY, MODE_VALUEREF, MODE_ALLREF } |
Functions | |
hash_table_element_t * | hash_table_element_new () |
void | hash_table_element_delete (hash_table_t *, hash_table_element_t *) |
uint16_t | hash_table_do_hash (void *key, size_t key_len, uint16_t max_key) |
hash_table_t * | hash_table_new (hash_table_mode_t) |
void | hash_table_delete (hash_table_t *) |
int | hash_table_add (hash_table_t *, void *, size_t, void *, size_t) |
int | hash_table_remove (hash_table_t *, void *, size_t) |
void * | hash_table_lookup (hash_table_t *, void *, size_t) |
int | hash_table_has_key (hash_table_t *, void *, size_t) |
size_t | hash_table_get_keys (hash_table_t *, void ***) |
size_t | hash_table_get_elements (hash_table_t *, hash_table_element_t ***) |
int | hash_table_resize (hash_table_t *, size_t) |
int | hash_table_iterate (hash_table_t *table, int(*fct)(void *user, void *value, void *key, size_t key_len), void *user) |
a simple hash table implementation
License GPLv3+
#define HASH | ( | x, | |
y | |||
) | hash_table_do_hash(x,y,HASH_LEN) |
#define HASH_LEN table->key_num |
#define hash_table_element_s sizeof(hash_table_element_t) |
#define hash_table_s sizeof(hash_table_t) |
#define HT_ADD | ( | table, | |
key, | |||
value | |||
) | hash_table_add(table, (void *) key, sizeof(*key), (void *) value, sizeof(*value)) |
macro to add a key - value pair to the hash table
table | hash table to add element to |
key | pointer to the key for the hash table |
value | pointer to the value to be added against the key |
#define HT_HAS_KEY | ( | table, | |
key | |||
) | hash_table_has_key(table, key, sizeof(*key)) |
macro to look if the exists in the hash table
key | pointer to key to be looked for |
#define HT_LOOKUP | ( | table, | |
key | |||
) | hash_table_lookup(table, key, sizeof(*key)) |
macro to lookup a key in a particular table
table | table to look key in |
key | pointer to key to be looked for |
#define HT_REMOVE | ( | table, | |
key | |||
) | hash_table_remove(table, key, sizeof(*key)) |
macro to remove an hash table element (for a given key) from a given hash table
table | hash table from which element has to be removed |
key | pointer to the key which has to be removed |
typedef struct hash_table_element hash_table_element_t |
typedef enum hash_table_mode hash_table_mode_t |
typedef struct hash_table hash_table_t |
enum hash_table_mode |
int hash_table_add | ( | hash_table_t * | table, |
void * | key, | ||
size_t | key_len, | ||
void * | value, | ||
size_t | value_len | ||
) |
Function to add a key - value pair to the hash table, use HT_ADD macro
table | hash table to add element to |
key | pointer to the key for the hash table |
key_len | length of the key in bytes |
value | pointer to the value to be added against the key |
value_len | length of the value in bytes |
void hash_table_delete | ( | hash_table_t * | table | ) |
Function to delete the hash table
table | hash table to be deleted |
uint16_t hash_table_do_hash | ( | void * | key, |
size_t | key_len, | ||
uint16_t | max_key | ||
) |
Function that returns a hash value for a given key and key_len
key | pointer to the key |
key_len | length of the key |
max_key | max value of the hash to be returned by the function |
void hash_table_element_delete | ( | hash_table_t * | table, |
hash_table_element_t * | element | ||
) |
Function to delete an hash table element
table | table from which element has to be deleted |
element | hash table element to be deleted |
hash_table_element_t* hash_table_element_new | ( | ) |
Function to create a now hash_table element
size_t hash_table_get_elements | ( | hash_table_t * | table, |
hash_table_element_t *** | elements | ||
) |
Function to get all elements (key - value pairs) from the given hash table
table | hash table from which elements have to be retrieved |
elements | a pointer to an array of hash_table_element_t pointer (malloced by function) |
size_t hash_table_get_keys | ( | hash_table_t * | table, |
void *** | keys_ptr | ||
) |
Function to return all the keys in a given hash table
table | hash table from which key are to be reterived |
keys | a void** pointer where keys are filled in (memory allocated internally and must be freed) |
int hash_table_has_key | ( | hash_table_t * | table, |
void * | key, | ||
size_t | key_len | ||
) |
Function to look if the exists in the hash table
key | pointer to key to be looked for |
key_len | size of the key to be searched |
int hash_table_iterate | ( | hash_table_t * | table, |
int(*)(void *user, void *value, void *key, size_t key_len) | fct, | ||
void * | user | ||
) |
Function to iterate through all elements of the hashtable
table | hash table to be iterated |
fct | pointer to a function returning 1 if the element has to be removed |
user | arbitrary user pointer passed to the fct callback |
void* hash_table_lookup | ( | hash_table_t * | table, |
void * | key, | ||
size_t | key_len | ||
) |
Function to lookup a key in a particular table
table | table to look key in |
key | pointer to key to be looked for |
key_len | size of the key to be searched |
Function to lookup a key in a particular table
table | table to look key in |
key | pointer to key to be looked for |
key_len | size of the key to be searched |
hash_table_t* hash_table_new | ( | hash_table_mode_t | mode | ) |
Fuction to create a new hash table
mode | hash_table_mode which the hash table should follow |
int hash_table_remove | ( | hash_table_t * | table, |
void * | key, | ||
size_t | key_len | ||
) |
Function to remove an hash table element (for a given key) from a given hash table
table | hash table from which element has to be removed |
key | pointer to the key which has to be removed |
key_len | size of the key in bytes |
int hash_table_resize | ( | hash_table_t * | table, |
size_t | len | ||
) |
Function to resize the hash table store house
table | hash table to be resized |
len | new length of the hash table |