Defines | |
| #define | HASH_TABLE_SIZE 65535 |
| Hash table size. | |
Typedefs | |
| typedef unsigned int(* | t_hash_fn )(void *) |
| Hash function type. | |
| typedef int(* | t_hash_key_compare_fn )(void *, void *) |
| Keys comparison function type. | |
| typedef void *(* | t_hash_key_copy_fn )(void *) |
| Key copy function type. | |
| typedef void(* | t_hash_key_free_fn )(void *) |
| Free key function type. | |
| typedef struct s_hash | t_hash |
| Hash type. | |
Functions | |
| void * | hash_find (t_hash *, void *) |
| Find hash value with given key. | |
| void | hash_add (t_hash *, void *, void *) |
| Adds new value with given key. | |
| void | hash_del (t_hash *, void *) |
| Deletes element with given key. | |
| t_hash * | hash_create (t_hash_key_compare_fn, t_hash_key_copy_fn, t_hash_key_free_fn, t_hash_fn) |
| Create hash using given functions for keys manipulations. | |
| t_hash * | hash_create_strkey () |
| Create hash with char* keys. | |
| void | hash_free (t_hash *) |
| Frees hash and releases occupied memory. | |
Hash is a data structure to speed up data searching based on keys. This file contains functions to create and handle hash structures.
| #define HASH_TABLE_SIZE 65535 |
Hash table size.
Size of a virtual hash table. The bigger is it, the more memory it consumes, but works faster.
| typedef struct s_hash t_hash |
Hash type.
Contains hash structure.
| typedef unsigned int(* t_hash_fn)(void *) |
Hash function type.
Function converting key to integer in range 0 to HASH_TABLE_SIZE.
| typedef int(* t_hash_key_compare_fn)(void *, void *) |
Keys comparison function type.
Function returning -1 0 or 1 depending on keys comparison.
| typedef void*(* t_hash_key_copy_fn)(void *) |
Key copy function type.
Function returning a copy of key.
| typedef void(* t_hash_key_free_fn)(void *) |
Free key function type.
Function freeing passed key.
| void hash_add | ( | t_hash * | hash, | |
| void * | key, | |||
| void * | data | |||
| ) |
Adds new value with given key.
Adds hash element with given key and value.
| hash | hash to add to. | |
| key | key to add. | |
| data | element data. |
| t_hash* hash_create | ( | t_hash_key_compare_fn | cmp, | |
| t_hash_key_copy_fn | cpy, | |||
| t_hash_key_free_fn | kfree, | |||
| t_hash_fn | hash_fn | |||
| ) |
Create hash using given functions for keys manipulations.
Creates hash using given functions for keys manipulations.
| cmp | comparison function. | |
| cpy | function for copying keys. | |
| kfree | function for releasing memory occupied by key. | |
| hash_fn | hash function. |
| t_hash* hash_create_strkey | ( | ) |
Create hash with char* keys.
Automatically creates hash using existing functions for char* keys manipulations.
| void hash_del | ( | t_hash * | hash, | |
| void * | key | |||
| ) |
Deletes element with given key.
Deletes hash element with given key.
| hash | hash to delete from. | |
| key | key to delete. |
| void* hash_find | ( | t_hash * | hash, | |
| void * | key | |||
| ) |
Find hash value with given key.
Finds hash element with given key and returns its value.
| hash | hash to search in. | |
| key | key for which to search. |
| void hash_free | ( | t_hash * | hash | ) |
Frees hash and releases occupied memory.
Releases memory occupied by the hash. Deletes all hash elements.
WARNING: if you don't keep your data pointers anywhere else, you will lose all the data,
| hash | hash to add to. |
1.5.5