My Project
programmer's documentation
Loading...
Searching...
No Matches
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
38extern "C" {
39#endif /* __cplusplus */
40
41/*============================================================================
42 * Enum definition
43 *============================================================================*/
44
60
61/*============================================================================
62 * Type definition
63 *============================================================================*/
64
69typedef double (*func1_t) (double);
70
75typedef double (*func2_t) (double, double);
76
81typedef double (*func3_t) (double, double, double);
82
87typedef double (*func4_t) (double, double, double, double);
88
93typedef union {
94 double value;
97} data_t;
98
103struct item {
104 char *key;
107 struct item *next;
108};
109
114struct HashTable {
117 int record;
118 int length;
119 struct item **table;
120};
121
126typedef 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
141void 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
152void 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
162void 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
175struct 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
191void
192mei_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
210struct 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
221void 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
232
233/*----------------------------------------------------------------------------*/
234
235#ifdef __cplusplus
236}
237#endif /* __cplusplus */
238
239#endif /* __MEI_HASH_TABLE_H__ */
240
mei_flag_t
List of the different type of symbol.
Definition mei_hash_table.h:49
@ ID
Definition mei_hash_table.h:52
@ FUNC2
Definition mei_hash_table.h:54
@ FUNC3
Definition mei_hash_table.h:55
@ OPR
Definition mei_hash_table.h:57
@ FUNC1
Definition mei_hash_table.h:53
@ CONSTANT
Definition mei_hash_table.h:51
@ FUNC4
Definition mei_hash_table.h:56
double(* func4_t)(double, double, double, double)
Type definition for pointer to a function of for arguments.
Definition mei_hash_table.h:87
void mei_hash_table_init(hash_table_t *htable)
Initialize the hash table with default symbols.
Definition mei_hash_table.c:317
double(* func3_t)(double, double, double)
Type definition for pointer to a function of three arguments.
Definition mei_hash_table.h:81
void mei_hash_table_dump(hash_table_t *htable)
Dump of table contents for debuging purpose.
Definition mei_hash_table.c:408
void mei_hash_table_item_print(struct item *item)
Dump function of a single record.
Definition mei_hash_table.c:385
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
double(* func2_t)(double, double)
Type definition for pointer to a function of two arguments.
Definition mei_hash_table.h:75
double(* func1_t)(double)
Type definition for a pointer to a function of one argument.
Definition mei_hash_table.h:69
void mei_hash_table_free(hash_table_t *htable)
Destroy a hash table.
Definition mei_hash_table.c:283
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
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
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
Structure defining a hash table.
Definition mei_hash_table.h:114
struct item ** table
Definition mei_hash_table.h:119
int length
Definition mei_hash_table.h:118
int record
Definition mei_hash_table.h:117
int n_inter
Definition mei_hash_table.h:115
Type definition for each record of the hash table.
Definition mei_hash_table.h:103
char * key
Definition mei_hash_table.h:104
data_t * data
Definition mei_hash_table.h:106
mei_flag_t type
Definition mei_hash_table.h:105
struct item * next
Definition mei_hash_table.h:107
Type definition for data of each element contained in the hash table.
Definition mei_hash_table.h:93
func1_t func
Definition mei_hash_table.h:95
func2_t f2
Definition mei_hash_table.h:96
double value
Definition mei_hash_table.h:94