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-2015 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,
59 
60 } mei_flag_t;
61 
62 /*============================================================================
63  * Type definition
64  *============================================================================*/
65 
70 typedef double (*func1_t) (double);
71 
76 typedef double (*func2_t) (double, double);
77 
82 typedef double (*func3_t) (double, double, double);
83 
88 typedef double (*func4_t) (double, double, double, double);
89 
94 typedef double (*interp1d_t) (char*, int, int, double);
95 
100 typedef union {
101  double value;
105 } data_t;
106 
111 struct item {
112  char *key;
115  struct item *next;
116 };
117 
122 struct HashTable {
123  int n_inter;
125  int record;
126  int length;
127  struct item **table;
128 };
129 
134 typedef struct HashTable hash_table_t;
135 
136 
137 /*============================================================================
138  * Public function prototypes
139  *============================================================================*/
140 
141 /*----------------------------------------------------------------------------
142  * Initialize the hash table to the size (modulo) asked for.
143  * Allocates space for the correct number of pointers and sets them to NULL.
144  *
145  * param [in] htable hash table
146  * param [in] modulo size of the hash table
147  *----------------------------------------------------------------------------*/
148 
149 void mei_hash_table_create(hash_table_t *const htable,
150  const int modulo);
151 
152 /*----------------------------------------------------------------------------*/
153 /*
154  * Initialize the hash table with default symbols
155  *
156  * param [in] htable hash table
157  */
158 /*----------------------------------------------------------------------------*/
159 
160 void mei_hash_table_init(hash_table_t *htable);
161 
162 /*----------------------------------------------------------------------------*/
163 /*
164  * Destroy a hash table.
165  *
166  * param [in] htable hash table
167  */
168 /*----------------------------------------------------------------------------*/
169 
170 void mei_hash_table_free(hash_table_t *htable);
171 
172 /*----------------------------------------------------------------------------*/
173 /*
174  * Find a record in a hash table.
175  *
176  * param [in] htable hash table
177  * param [in] key key
178  *
179  * return a pointer containing the record
180  */
181 /*----------------------------------------------------------------------------*/
182 
183 struct item * mei_hash_table_lookup(hash_table_t *htable,
184  const char *key);
185 
186 /*----------------------------------------------------------------------------*/
187 /*
188  * Insert a record in a hash table.
189  *
190  * param [in] htable hash table
191  * param [in] key key associated to the record
192  * param [in] type flag associated to the record
193  * param [in] value store a value if the record if a real
194  * param [in] f1 pointer on a one argument function
195  * param [in] f2 pointer on a two argument function
196  * param [in] f3 pointer on a three argument function
197  * param [in] f4 pointer on a four argument function
198  * param [in] i1d pointer on a 1D interpolation function
199  */
200 /*----------------------------------------------------------------------------*/
201 
202 void
203 mei_hash_table_insert(hash_table_t *const htable,
204  const char *const key,
205  const mei_flag_t type,
206  const double value,
207  const func1_t func,
208  const func2_t f2,
209  const func3_t f3,
210  const func4_t f4,
211  const interp1d_t i1d);
212 
213 /*----------------------------------------------------------------------------*/
214 /*
215  * Find a record in a hash table.
216  *
217  * param [in] htable hash table
218  * param [in] key key
219  *
220  * return a pointer containing the record
221  */
222 /*----------------------------------------------------------------------------*/
223 
224 struct item* mei_hash_table_find(hash_table_t *htable,
225  const char *key);
226 
227 /*----------------------------------------------------------------------------*/
228 /*
229  * Dump of table contents for debuging purpose.
230  *
231  * param [in] htable hash table
232  */
233 /*----------------------------------------------------------------------------*/
234 
235 void mei_hash_table_dump(hash_table_t *htable);
236 
237 /*----------------------------------------------------------------------------*/
238 /*
239  * Dump function of a single record.
240  *
241  * param [in] item record
242  */
243 /*----------------------------------------------------------------------------*/
244 
245 void mei_hash_table_item_print(struct item *item);
246 
247 /*----------------------------------------------------------------------------*/
248 
249 #ifdef __cplusplus
250 }
251 #endif /* __cplusplus */
252 
253 #endif /* __MEI_HASH_TABLE_H__ */
254 
int record
Definition: mei_hash_table.h:125
double(* interp1d_t)(char *, int, int, double)
Type definition for pointer to a function of for 1D interpolation.
Definition: mei_hash_table.h:94
struct item ** table
Definition: mei_hash_table.h:127
Definition: mei_hash_table.h:55
Definition: mei_hash_table.h:54
Type definition for each record of the hash table.
Definition: mei_hash_table.h:111
void mei_hash_table_item_print(struct item *item)
Dump function of a single record.
Definition: mei_hash_table.c:425
Definition: mei_hash_table.h:57
int length
Definition: mei_hash_table.h:126
int n_inter
Definition: mei_hash_table.h:123
Structure defining a hash table.
Definition: mei_hash_table.h:122
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 func, const func2_t f2, const func3_t f3, const func4_t f4, const interp1d_t i1d)
Insert a record in a hash table.
Definition: mei_hash_table.c:197
void mei_hash_table_dump(hash_table_t *htable)
Dump of table contents for debuging purpose.
Definition: mei_hash_table.c:449
char * key
Definition: mei_hash_table.h:112
Definition: mei_hash_table.h:56
mei_flag_t type
Definition: mei_hash_table.h:113
double(* func4_t)(double, double, double, double)
Type definition for pointer to a function of for arguments.
Definition: mei_hash_table.h:88
double precision, dimension(ncharm), save f2
Definition: cpincl.f90:226
data_t * data
Definition: mei_hash_table.h:114
Definition: mei_hash_table.h:58
mei_flag_t
List of the different type of symbol.
Definition: mei_hash_table.h:49
func1_t func
Definition: mei_hash_table.h:102
double(* func1_t)(double)
Type definition for a pointer to a function of one argument.
Definition: mei_hash_table.h:70
double(* func2_t)(double, double)
Type definition for pointer to a function of two arguments.
Definition: mei_hash_table.h:76
interp1d_t i1d
Definition: mei_hash_table.h:104
void mei_hash_table_free(hash_table_t *htable)
Destroy a hash table.
Definition: mei_hash_table.c:294
double value
Definition: mei_hash_table.h:101
double(* func3_t)(double, double, double)
Type definition for pointer to a function of three arguments.
Definition: mei_hash_table.h:82
struct item * next
Definition: mei_hash_table.h:115
Definition: mei_hash_table.h:52
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:132
func2_t f2
Definition: mei_hash_table.h:103
void mei_hash_table_init(hash_table_t *htable)
Initialize the hash table with default symbols.
Definition: mei_hash_table.c:328
Definition: mei_hash_table.h:53
Type definition for data of each element contained in the hash table.
Definition: mei_hash_table.h:100
Definition: mei_hash_table.h:51
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:262
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:162