Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
last version of tesh
[simgrid.git] / tools / tesh2 / include / htable.h
1 #ifndef __HTABLE
2 #define __HTABLE
3
4
5 #include <allocator.h>
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 #ifndef __FN_FINALIZE_T_DEFINED
12 typedef int (*fn_finalize_t)(void**);
13 #define __FN_FINALIZE_T_DEFINED
14 #endif
15
16
17 /* 
18  * pointer to a compare key function.
19  * the function takes two items to compare and returns true if they are equal.
20  */
21 #ifndef __FN_CMP_KEY_T_DEFINED
22 typedef int (*fn_cmp_key_t)(const void*, const void*);
23 #define __FN_CMP_KEY_T_DEFINED
24 #endif
25
26 /* 
27  * pointer to a hash function.
28  * the function take the value to compute the hash value that it returns.
29  */ 
30 #ifndef __FN_HFUNC_T_DEFINED
31 typedef unsigned int (*fn_hfunc_t)(const void*);
32 #define __FN_HFUNC_T_DEFINED
33 #endif
34
35 typedef struct s_hassoc
36 {
37                 struct s_hassoc* next;
38                 const void* key;
39                 const void* val;
40 }s_hassoc_t,* hassoc_t;
41
42 typedef struct s_htable
43 {
44         hassoc_t* content;                      /* the hache table content                                                                      */
45         int size;                       /* the size of the hash table                                                   */
46         allocator_t allocator;          /* the allocator used to allocate the associations              */
47         fn_hfunc_t fn_hfunc;                    /* a pointer to the hash function to use                                */
48         fn_cmp_key_t fn_cmp_key;        /* a pointer to the function used to fn_cmp_key the key */
49         fn_finalize_t fn_finalize;
50 }s_htable_t,* htable_t;
51
52
53
54
55
56 htable_t
57 htable_new(
58                                 int block_capacity,                                                     /* the block capacity of the blocks of the allocator used by the htable */ 
59                                 int size,                                                       /* the size of the table size                                                                                   */ 
60                                 fn_hfunc_t fn_hfunc,                                                    /* the pointer to the function to use                                                                   */ 
61                                 fn_cmp_key_t fn_cmp_key,                                        /* the pointer to the function used to fn_cmp_key the keys of the assocs        */ 
62                                 fn_finalize_t fn_finalize               /* the pointer to the function used to destroy the values of the assocs */
63                         );
64
65 int
66 htable_set(htable_t htable, const void* key, const void* val);
67
68 void*
69 htable_lookup(htable_t htable, const void* key);
70
71 void*
72 htable_remove(htable_t htable, const void* key);
73
74 int
75 htable_erase(htable_t htable, const void* key);
76
77 int
78 htable_free(htable_t* htableptr);
79
80 int
81 htable_clear(htable_t htable);
82
83 int
84 htable_get_size(htable_t htable);
85
86 int
87 htable_is_empty(htable_t htable);
88
89 int
90 htable_is_autodelete(htable_t htable);
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #endif /* !__HTABLE */
97