programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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-2013 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 mei_hash_table_insert(hash_table_t *const htable,
203  const char *const key,
204  const mei_flag_t type,
205  const double value,
206  const func1_t func,
207  const func2_t f2,
208  const func3_t f3,
209  const func4_t f4,
210  const interp1d_t i1d);
211 
212 /*----------------------------------------------------------------------------*/
213 /*
214  * Find a record in a hash table.
215  *
216  * param [in] htable hash table
217  * param [in] key key
218  *
219  * return a pointer containing the record
220  */
221 /*----------------------------------------------------------------------------*/
222 
223 struct item* mei_hash_table_find(hash_table_t *htable,
224  const char *key);
225 
226 /*----------------------------------------------------------------------------*/
227 /*
228  * Dump of table contents for debuging purpose.
229  *
230  * param [in] htable hash table
231  */
232 /*----------------------------------------------------------------------------*/
233 
234 void mei_hash_table_dump(hash_table_t *htable);
235 
236 /*----------------------------------------------------------------------------*/
237 /*
238  * Dump function of a single record.
239  *
240  * param [in] item record
241  */
242 /*----------------------------------------------------------------------------*/
243 
244 void mei_hash_table_item_print(struct item *item);
245 
246 /*----------------------------------------------------------------------------*/
247 
248 #ifdef __cplusplus
249 }
250 #endif /* __cplusplus */
251 
252 #endif /* __MEI_HASH_TABLE_H__ */
253