28void destroy_data(
void *ptr )
45 n_log(
LOG_INFO,
"Filling HashTable with %d random elements", NB_ELEMENTS );
46 for(
int it = 0 ; it < NB_ELEMENTS ; it ++ )
49 int randomizator = rand()%4;
50 nstrprintf( nkey,
"key%d_%d", it, randomizator );
51 switch( randomizator )
65 data -> rnd_str = NULL ;
69 n_log(
LOG_INFO,
"Put ptr rnd_str %s value %d with key %s",
_nstr( data -> rnd_str ), data -> value,
_nstr( nkey ) );
73 sprintf( str,
"%s%d",
_nstr( nkey ), rand()%10 );
86 n_log(
LOG_INFO,
"HT_FOREACH hash: %u, key:%s", node -> hash_value ,
_str( node -> key ) );
90 n_log(
LOG_INFO,
"HT_FOREACH_R hash: %u, key:%s", node -> hash_value ,
_str( node -> key ) );
96 n_log(
LOG_INFO,
"table size: %ld , table optimal size: %ld", htable -> size, optimal_size );
103 n_log(
LOG_ERR,
"Error when optimizing table %p", htable );
130 n_log(
LOG_INFO,
"completion result: %s", (
char *)node -> ptr );
137 if( strncasecmp(
"key", node -> key, 3 ) == 0 )
141 results =
ht_search( htable, &matching_nodes );
165 char *
string = NULL ;
174 n_log(
LOG_INFO,
"completion result: %s", (
char *)node -> ptr );
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define _str(__PTR)
define true
#define Free(__ptr)
Free Handler to get errors.
#define _nstr(__PTR)
N_STR or "NULL" string for logging purposes.
int ht_get_int(HASH_TABLE *table, const char *key, int *val)
get node at 'key' from 'table'
LIST * ht_search(HASH_TABLE *table, int(*node_is_matching)(HASH_NODE *node))
seach table for matching nodes
int destroy_ht(HASH_TABLE **table)
empty a table and destroy it
#define HT_FOREACH_R(__ITEM_, __HASH_, __ITERATOR,...)
ForEach macro helper.
HASH_TABLE * new_ht(size_t size)
Create a hash table with the given size.
int ht_get_table_collision_percentage(HASH_TABLE *table)
get table collision percentage (HASH_CLASSIC mode only)
int ht_get_double(HASH_TABLE *table, const char *key, double *val)
get double at 'key' from 'table'
int empty_ht(HASH_TABLE *table)
empty a table
LIST * ht_get_completion_list(HASH_TABLE *table, const char *keybud, size_t max_results)
get next matching keys in table tree
int ht_put_double(HASH_TABLE *table, const char *key, double value)
put a double value with given key in the targeted hash table
int ht_get_string(HASH_TABLE *table, const char *key, char **val)
get string at 'key' from 'table'
int ht_put_string(HASH_TABLE *table, const char *key, char *string)
put a string value (copy/dup) with given key in the targeted hash table
int ht_resize(HASH_TABLE **table, size_t size)
rehash table according to size (HASH_CLASSIC mode only)
HASH_TABLE * new_ht_trie(size_t alphabet_length, size_t alphabet_offset)
create a TRIE hash table with the alphabet_size, each key value beeing decreased by alphabet_offset
int ht_put_int(HASH_TABLE *table, const char *key, int value)
put an integral value with given key in the targeted hash table
int ht_put_ptr(HASH_TABLE *table, const char *key, void *ptr, void(*destructor)(void *ptr))
put a pointer to the string value with given key in the targeted hash table
int ht_optimize(HASH_TABLE **table)
try an automatic optimization of the table
int ht_get_optimal_size(HASH_TABLE *table)
get optimal array size based on nb=(number_of_key*1.3) && if( !isprime(nb) )nb=nextprime(nb) (HASH_CL...
#define HT_FOREACH(__ITEM_, __HASH_,...)
ForEach macro helper.
structure of a hash table node
structure of a hash table
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper.
int list_destroy(LIST **list)
Empty and Free a list container.
LIST * new_generic_list(int max_items)
Initialiaze a generic list container to max_items pointers.
Structure of a generic LIST container.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_INFO
informational
void free_nstr_ptr(void *ptr)
Free a N_STR pointer structure.
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
#define nstrprintf(__nstr_var,...)
Macro to quickly allocate and sprintf to N_STR *.
A box including a string and his lenght.
Hash functions and table.
List structures and definitions.
N_STR and string function declaration.
N_STR * rnd_str
string holder