Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Hash_Table.h
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 
25 #ifndef HASH_TABLE_H
26 #define HASH_TABLE_H
27 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <stdint.h>
36 
37 #include "Chained_List.h"
38 #include "Spinlock.h"
39 #include "CRC64.h"
40 
47  int count;
48 };
49 
53 struct Hash_Table {
54  void *payload;
55  size_t sizeof_payload;
57  uint64_t table_size;
58  uint8_t need_lock;
59  uint8_t __attribute__ ((aligned (64))) coll_avoid;
60 };
61 
66 static inline void Hash_Table_use_lock( struct Hash_Table *ht )
67 {
68  ht->need_lock = 1;
69 }
70 
71 /* Interface */
72 
85 void Hash_Table_init( struct Hash_Table *ht, size_t sizeof_payload, uint64_t table_size, uint8_t coll_avoid );
86 
92 void Hash_Table_release( struct Hash_Table *ht, void (*free_f)(void *) );
93 
111 void * Hash_Table_get( struct Hash_Table *ht, uint64_t key , void *extra_arg, int (*test_func)(void *, uint64_t , void *));
112 
120 void * Hash_Table_push( struct Hash_Table *ht, void *payload , uint64_t key );
121 
128 void* Hash_Table_get_an_entry( struct Hash_Table *ht );
129 
139 void * Hash_Table_push_unique( struct Hash_Table *ht, void *payload , uint64_t key, void *extra_arg, int (*test_func)(void *, uint64_t, void * ) );
140 
146 uint64_t Hash_Table_count_by_walk(struct Hash_Table *ht);
161 void Hash_Table_walkthrought( struct Hash_Table *ht, void (*action)(void *) );
162 
169 void Hash_Table_walkthrought_2p( struct Hash_Table *ht, void *second_arg, void (*action)(void *, void *) );
170 
178 void Hash_Table_walkthrought_3p( struct Hash_Table *ht, void *second_arg, void *third_arg, void (*action)(void *, void *, void *) );
179 
187 void Hash_Table_walkthrought_cond( struct Hash_Table *ht, void (*action)(void *), int (*test_func)(void *, void * ), void *test_value );
188 
197 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 );
212 void Hash_Table_lock_cell( struct Hash_Table *ht, uint64_t key );
213 
219 void Hash_Table_unlock_cell( struct Hash_Table *ht, uint64_t key );
220 
227 void Hash_Table_init_Internal( void *phi, uint64_t coll_avoid, uint64_t intern_payload_size );
228 
233 void Hash_Table_release_Internal( void *phi );
234 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif
245 
int count
the number of elements
Definition: Hash_Table.h:47
static void Hash_Table_use_lock(struct Hash_Table *ht)
Indicates that the hashtable must use a lock for operations (get/push)
Definition: Hash_Table.h:66
This is the structure used to store the clusters (items that have the same hash)
Definition: Hash_Table.h:44
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.
Definition: Hash_Table.c:232
uint8_t coll_avoid
maximum number of elements stored in the cluster static array
Definition: Hash_Table.h:59
void Hash_Table_release_Internal(void *phi)
Releases internal hashtable data.
Definition: Hash_Table.c:30
size_t intern_payload_size
the size of the internal static array (coll_avoid * sizeof_payload)
Definition: Hash_Table.h:56
void Hash_Table_lock_cell(struct Hash_Table *ht, uint64_t key)
Locks a cell at given key.
Definition: Hash_Table.c:105
void * Hash_Table_push(struct Hash_Table *ht, void *payload, uint64_t key)
adds an element to a hashtable
Definition: Hash_Table.c:198
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.
Definition: Hash_Table.c:184
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.
Definition: Hash_Table.c:282
This a structure wrapps the use of chained_list This is the main chain list structure to use...
Definition: Chained_List.h:273
size_t sizeof_payload
the size of stored elements
Definition: Hash_Table.h:55
void Hash_Table_unlock_cell(struct Hash_Table *ht, uint64_t key)
Unlocks a cell at given key.
Definition: Hash_Table.c:117
This is the main hask table structure.
Definition: Hash_Table.h:53
void Hash_Table_init(struct Hash_Table *ht, size_t sizeof_payload, uint64_t table_size, uint8_t coll_avoid)
Hash_Table initialization.
Definition: Hash_Table.c:40
void Hash_Table_walkthrought_2p(struct Hash_Table *ht, void *second_arg, void(*action)(void *, void *))
Executes a function on every stored elements.
Definition: Hash_Table.c:385
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
Definition: Hash_Table.c:128
uint64_t Hash_Table_count_by_walk(struct Hash_Table *ht)
counts the elements in the hashtable by walking through all the elements
Definition: Hash_Table.c:425
void Hash_Table_release(struct Hash_Table *ht, void(*free_f)(void *))
Hash_Table release.
Definition: Hash_Table.c:67
void * payload
where data is stored (Hash_Table_Internal + cluster static array)
Definition: Hash_Table.h:54
volatile unsigned int MALP_Spinlock
The type of spinlocks in MALP.
Definition: Spinlock.h:63
uint64_t table_size
the size of the table
Definition: Hash_Table.h:57
void * Hash_Table_get_an_entry(struct Hash_Table *ht)
Retrieves the first found element of the hash table.
Definition: Hash_Table.c:329
uint8_t need_lock
set to 1 if internals need to use a lock before access
Definition: Hash_Table.h:58
MALP_Spinlock lock
a lock for concurrent access
Definition: Hash_Table.h:45
struct Chained_List next_pl
the actual chained list (containing elements)
Definition: Hash_Table.h:46
void Hash_Table_walkthrought(struct Hash_Table *ht, void(*action)(void *))
Executes a function on every stored elements.
Definition: Hash_Table.c:350
void Hash_Table_init_Internal(void *phi, uint64_t coll_avoid, uint64_t intern_payload_size)
Initializes internal hashtable data.
Definition: Hash_Table.c:22
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.
Definition: Hash_Table.c:435