51 ht->payload = malloc( table_size * sizeof_payload + table_size );
54 printf(
"Failled to alloc a %ld byte Hash table in %s at %d \n",table_size * sizeof_payload , __FILE__, __LINE__);
60 for( i = 0 ; i < table_size ; i++) {
151 for( i = 0 ; (i < phi->
count) && (i < ht->coll_avoid) ; i++ ) {
155 if( test_func( ptr , key, extra_arg ) ) {
167 for( i = 0 ; i < cc_len ; i++) {
171 if( test_func( ptr , key, extra_arg ) ) {
202 void *dest_ptr = NULL;
209 void *payload_ptr = phi + 1;
235 int i = 0, j = 0, k=0;
237 void *payload = NULL;
245 if( phi->
count == 0 )
248 payload = ( phi + 1 );
269 for( k = 0 ; k < cc_len ; k++) {
274 (action) ( payload );
275 }
else if( (test_func )( payload , test_value ) ) {
276 (action) ( payload );
288 int i = 0, j = 0, k=0;
290 void *payload = NULL;
295 if( phi->
count == 0 )
298 payload = ( phi + 1 );
314 for( k = 0 ; k < cc_len ; k++) {
319 (action) ( payload , second_arg);
320 }
else if( (test_func )( payload , test_value ) ) {
321 (action) ( payload, second_arg);
333 void *payload = NULL;
338 if( phi->
count == 0 )
341 payload = ( phi + 1 );
353 int i = 0, j = 0, k=0;
355 void *payload = NULL;
360 if( phi->
count == 0 )
363 payload = ( phi + 1 );
376 for( k = 0 ; k < cc_len ; k++) {
379 (action) ( payload );
388 int i = 0, j = 0, k=0;
390 void *payload = NULL;
395 if( phi->
count == 0 )
398 payload = ( phi + 1 );
410 for( k = 0 ; k < cc_len ; k++) {
413 (action) ( payload , second_arg );
421 uint64_t *counter = (uint64_t *)pcounter;
422 *counter = *counter + 1;
438 int i = 0, j = 0, k=0;
440 void *payload = NULL;
445 if( phi->
count == 0 )
448 payload = ( phi + 1 );
460 for( k = 0 ; k < cc_len ; k++) {
463 (action) ( payload , second_arg , third_arg);
static uint64_t MALP_Trace_crc64(char *source, uint64_t size)
Computes the hash of a given data.
int count
the number of elements
This struct is used to improve performance when sequentially walking through.
static void * get_cell_at(struct Hash_Table *ht, uint64_t key)
static void chained_list_view_init(struct chained_list_view *clv)
Initializes a chained_list_view.
void ___Hash_Table_count_by_walk(void *elem, void *pcounter)
This is the structure used to store the clusters (items that have the same hash)
void Hash_Table_walkthrought_cond(struct Hash_Table *ht, void(*action)(void *), int(*test_func)(void *, void *), void *test_value)
Executes a function on every stored elements that satisfy a condition.
uint8_t coll_avoid
maximum number of elements stored in the cluster static array
void Hash_Table_release_Internal(void *phi)
Releases internal hashtable data.
size_t intern_payload_size
the size of the internal static array (coll_avoid * sizeof_payload)
void Hash_Table_lock_cell(struct Hash_Table *ht, uint64_t key)
Locks a cell at given key.
void * Hash_Table_push(struct Hash_Table *ht, void *payload, uint64_t key)
adds an element to a hashtable
void * Hash_Table_push_unique(struct Hash_Table *ht, void *payload, uint64_t key, void *extra_arg, int(*test_func)(void *, uint64_t, void *))
Adds an element into the hashtable. Replaces already existing element at key.
static void Chained_List_init(struct Chained_List *list, uint64_t chunk_size, size_t payload_size)
Initializes a Chained_List.
void Hash_Table_walkthrought_cond_2p(struct Hash_Table *ht, void *second_arg, void(*action)(void *, void *), int(*test_func)(void *, void *), void *test_value)
Executes a function on every stored elements that satisfy a condition.
int MALP_Spinlock_unlock(MALP_Spinlock *mutex)
Unlocks the given MALP_Spinlock.
static uint64_t Chained_List_count(struct Chained_List *list)
Counts the elements in the list.
size_t sizeof_payload
the size of stored elements
static void * Chained_List_push(struct Chained_List *list, void *payload)
Adds an element to the list.
void Hash_Table_unlock_cell(struct Hash_Table *ht, uint64_t key)
Unlocks a cell at given key.
This is the main hask table structure.
void Hash_Table_init(struct Hash_Table *ht, size_t sizeof_payload, uint64_t table_size, uint8_t coll_avoid)
Hash_Table initialization.
void Hash_Table_walkthrought_2p(struct Hash_Table *ht, void *second_arg, void(*action)(void *, void *))
Executes a function on every stored elements.
void * Hash_Table_get(struct Hash_Table *ht, uint64_t key, void *extra_arg, int(*test_func)(void *, uint64_t, void *))
retrieves an element from the hashtable
uint64_t Hash_Table_count_by_walk(struct Hash_Table *ht)
counts the elements in the hashtable by walking through all the elements
void Hash_Table_release(struct Hash_Table *ht, void(*free_f)(void *))
Hash_Table release.
int MALP_Spinlock_lock(MALP_Spinlock *mutex)
Locks the given MALP_Spinlock.
void * payload
where data is stored (Hash_Table_Internal + cluster static array)
uint64_t table_size
the size of the table
void * Hash_Table_get_an_entry(struct Hash_Table *ht)
Retrieves the first found element of the hash table.
static void Chained_List_release(struct Chained_List *list)
Clears a Chained_List.
uint8_t need_lock
set to 1 if internals need to use a lock before access
MALP_Spinlock lock
a lock for concurrent access
struct Chained_List next_pl
the actual chained list (containing elements)
void Hash_Table_walkthrought(struct Hash_Table *ht, void(*action)(void *))
Executes a function on every stored elements.
void Hash_Table_init_Internal(void *phi, uint64_t coll_avoid, uint64_t intern_payload_size)
Initializes internal hashtable data.
static void * Chained_List_get_nth_seq(struct Chained_List *cl, struct chained_list_view *view, uint64_t n)
Get a reference to the nth element of the chained list (optimised for sequential) ...
void Hash_Table_walkthrought_3p(struct Hash_Table *ht, void *second_arg, void *third_arg, void(*action)(void *, void *, void *))
Executes a function on every stored elements.