My Project
programmer's documentation
mei_hash_table.h
Go to the documentation of this file.
1 #ifndef __MEI_HASH_TABLE_H__
2 #define __MEI_HASH_TABLE_H__
3 
15 /*
16  This file is part of Code_Saturne, a general-purpose CFD tool.
17 
18  Copyright (C) 1998-2019 EDF S.A.
19 
20  This program is free software; you can redistribute it and/or modify it under
21  the terms of the GNU General Public License as published by the Free Software
22  Foundation; either version 2 of the License, or (at your option) any later
23  version.
24 
25  This program is distributed in the hope that it will be useful, but WITHOUT
26  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
27  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
28  details.
29 
30  You should have received a copy of the GNU General Public License along with
31  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
32  Street, Fifth Floor, Boston, MA 02110-1301, USA.
33 */
34 
35 /*----------------------------------------------------------------------------*/
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
40 
41 /*============================================================================
42  * Enum definition
43  *============================================================================*/
44 
49 typedef enum {
50 
52  ID,
58 
59 } mei_flag_t;
60 
61 /*============================================================================
62  * Type definition
63  *============================================================================*/
64 
69 typedef double (*func1_t) (double);
70 
75 typedef double (*func2_t) (double, double);
76 
81 typedef double (*func3_t) (double, double, double);
82 
87 typedef double (*func4_t) (double, double, double, double);
88 
93 typedef union {
94  double value;
97 } data_t;
98 
103 struct item {
104  char *key;
107  struct item *next;
108 };
109 
114 struct HashTable {
115  int n_inter;
117  int record;
118  int length;
119  struct item **table;
120 };
121 
126 typedef struct HashTable hash_table_t;
127 
128 
129 /*============================================================================
130  * Public function prototypes
131  *============================================================================*/
132 
133 /*----------------------------------------------------------------------------
134  * Initialize the hash table to the size (modulo) asked for.
135  * Allocates space for the correct number of pointers and sets them to NULL.
136  *
137  * param [in] htable hash table
138  * param [in] modulo size of the hash table
139  *----------------------------------------------------------------------------*/
140 
141 void mei_hash_table_create(hash_table_t *const htable,
142  const int modulo);
143 
144 /*----------------------------------------------------------------------------*/
145 /*
146  * Initialize the hash table with default symbols
147  *
148  * param [in] htable hash table
149  */
150 /*----------------------------------------------------------------------------*/
151 
152 void mei_hash_table_init(hash_table_t *htable);
153 
154 /*----------------------------------------------------------------------------*/
155 /*
156  * Destroy a hash table.
157  *
158  * param [in] htable hash table
159  */
160 /*----------------------------------------------------------------------------*/
161 
162 void mei_hash_table_free(hash_table_t *htable);
163 
164 /*----------------------------------------------------------------------------*/
165 /*
166  * Find a record in a hash table.
167  *
168  * param [in] htable hash table
169  * param [in] key key
170  *
171  * return a pointer containing the record
172  */
173 /*----------------------------------------------------------------------------*/
174 
175 struct item * mei_hash_table_lookup(hash_table_t *htable,
176  const char *key);
177 
178 /*----------------------------------------------------------------------------*/
179 /*
180  * Insert a record in a hash table.
181  *
182  * param [in] htable hash table
183  * param [in] key key associated to the record
184  * param [in] type flag associated to the record
185  * param [in] value store a value if the record if a real
186  * param [in] f1 pointer on a one argument function
187  * param [in] f2 pointer on a two argument function
188  */
189 /*----------------------------------------------------------------------------*/
190 
191 void
192 mei_hash_table_insert(hash_table_t *const htable,
193  const char *const key,
194  const mei_flag_t type,
195  const double value,
196  const func1_t f1,
197  const func2_t f2);
198 
199 /*----------------------------------------------------------------------------*/
200 /*
201  * Find a record in a hash table.
202  *
203  * param [in] htable hash table
204  * param [in] key key
205  *
206  * return a pointer containing the record
207  */
208 /*----------------------------------------------------------------------------*/
209 
210 struct item* mei_hash_table_find(hash_table_t *htable,
211  const char *key);
212 
213 /*----------------------------------------------------------------------------*/
214 /*
215  * Dump of table contents for debuging purpose.
216  *
217  * param [in] htable hash table
218  */
219 /*----------------------------------------------------------------------------*/
220 
221 void mei_hash_table_dump(hash_table_t *htable);
222 
223 /*----------------------------------------------------------------------------*/
224 /*
225  * Dump function of a single record.
226  *
227  * param [in] item record
228  */
229 /*----------------------------------------------------------------------------*/
230 
231 void mei_hash_table_item_print(struct item *item);
232 
233 /*----------------------------------------------------------------------------*/
234 
235 #ifdef __cplusplus
236 }
237 #endif /* __cplusplus */
238 
239 #endif /* __MEI_HASH_TABLE_H__ */
240 
CONSTANT
Definition: mei_hash_table.h:51
func4_t
double(* func4_t)(double, double, double, double)
Type definition for pointer to a function of for arguments.
Definition: mei_hash_table.h:87
HashTable::length
int length
Definition: mei_hash_table.h:118
FUNC2
Definition: mei_hash_table.h:54
func1_t
double(* func1_t)(double)
Type definition for a pointer to a function of one argument.
Definition: mei_hash_table.h:69
mei_flag_t
mei_flag_t
List of the different type of symbol.
Definition: mei_hash_table.h:49
HashTable::n_inter
int n_inter
Definition: mei_hash_table.h:115
item::key
char * key
Definition: mei_hash_table.h:104
func3_t
double(* func3_t)(double, double, double)
Type definition for pointer to a function of three arguments.
Definition: mei_hash_table.h:81
cpincl::f1
double precision, dimension(ncharm), save f1
Definition: cpincl.f90:233
mei_hash_table_init
void mei_hash_table_init(hash_table_t *htable)
Initialize the hash table with default symbols.
Definition: mei_hash_table.c:317
FUNC4
Definition: mei_hash_table.h:56
HashTable::table
struct item ** table
Definition: mei_hash_table.h:119
mei_hash_table_insert
void mei_hash_table_insert(hash_table_t *const htable, const char *const key, const mei_flag_t type, const double value, const func1_t f1, const func2_t f2)
Insert a record in a hash table.
Definition: mei_hash_table.c:192
mei_hash_table_free
void mei_hash_table_free(hash_table_t *htable)
Destroy a hash table.
Definition: mei_hash_table.c:283
cpincl::f2
double precision, dimension(ncharm), save f2
Definition: cpincl.f90:233
item
Type definition for each record of the hash table.
Definition: mei_hash_table.h:103
mei_hash_table_lookup
struct item * mei_hash_table_lookup(hash_table_t *htable, const char *key)
Find a record in a hash table.
Definition: mei_hash_table.c:251
func2_t
double(* func2_t)(double, double)
Type definition for pointer to a function of two arguments.
Definition: mei_hash_table.h:75
data_t
Type definition for data of each element contained in the hash table.
Definition: mei_hash_table.h:93
mei_hash_table_dump
void mei_hash_table_dump(hash_table_t *htable)
Dump of table contents for debuging purpose.
Definition: mei_hash_table.c:408
item::type
mei_flag_t type
Definition: mei_hash_table.h:105
data_t::value
double value
Definition: mei_hash_table.h:94
item::data
data_t * data
Definition: mei_hash_table.h:106
mei_hash_table_create
void mei_hash_table_create(hash_table_t *const htable, const int modulo)
Initialize the hash table to the size (modulo) asked for. Allocates space for the correct number of p...
Definition: mei_hash_table.c:130
data_t::f2
func2_t f2
Definition: mei_hash_table.h:96
data_t::func
func1_t func
Definition: mei_hash_table.h:95
OPR
Definition: mei_hash_table.h:57
ID
Definition: mei_hash_table.h:52
mei_hash_table_find
struct item * mei_hash_table_find(hash_table_t *htable, const char *key)
Find a record in a hash table.
Definition: mei_hash_table.c:160
HashTable::record
int record
Definition: mei_hash_table.h:117
mei_hash_table_item_print
void mei_hash_table_item_print(struct item *item)
Dump function of a single record.
Definition: mei_hash_table.c:385
type
void const cs_int_t * type
Definition: cs_measures_util.h:425
HashTable
Structure defining a hash table.
Definition: mei_hash_table.h:114
FUNC1
Definition: mei_hash_table.h:53
FUNC3
Definition: mei_hash_table.h:55
item::next
struct item * next
Definition: mei_hash_table.h:107