~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to src/mei/mei_hash_table.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __MEI_HASH_TABLE_H__
 
2
#define __MEI_HASH_TABLE_H__
 
3
 
 
4
/*!
 
5
 * \file mei_hash_table.h
 
6
 *
 
7
 * \brief Hash table, intended to provide a symbol table
 
8
 *
 
9
 * A hash table consists of an array of container. Each container
 
10
 * holds a copy of the key, a pointer to the data associated with the
 
11
 * key, and a pointer to the next container that associated with this one,
 
12
 * if there was one.
 
13
 */
 
14
 
 
15
/*
 
16
  This file is part of Code_Saturne, a general-purpose CFD tool.
 
17
 
 
18
  Copyright (C) 1998-2011 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
 
 
45
/*!
 
46
 * \brief List of the different type of symbol
 
47
 */
 
48
 
 
49
typedef enum { CONSTANT, ID, FUNC1, FUNC2, FUNC3, FUNC4, OPR } mei_flag_t;
 
50
 
 
51
/*============================================================================
 
52
 * Type definition
 
53
 *============================================================================*/
 
54
 
 
55
/*!
 
56
 * \brief Type definition for a pointer to a function of one argument
 
57
 */
 
58
 
 
59
typedef double (*func1_t) (double);
 
60
 
 
61
/*!
 
62
 * \brief Type definition for pointer to a function of two arguments
 
63
 */
 
64
 
 
65
typedef double (*func2_t) (double, double);
 
66
 
 
67
/*!
 
68
 * \brief Type definition for pointer to a function of three arguments
 
69
 */
 
70
 
 
71
typedef double (*func3_t) (double, double, double);
 
72
 
 
73
/*!
 
74
 * \brief Type definition for pointer to a function of for arguments
 
75
 */
 
76
 
 
77
typedef double (*func4_t) (double, double, double, double);
 
78
 
 
79
/*!
 
80
 * \brief Type definition for data of each element contained in the hash table
 
81
 */
 
82
 
 
83
typedef union {
 
84
  double value;    /*!< Constant or variable value.  */
 
85
  func1_t func;    /*!< Pointer to function with one argument */
 
86
  func2_t f2;      /*!< Pointer to function with two argument */
 
87
} data_t;
 
88
 
 
89
/*!
 
90
 * \brief Type definition for each bucket of the hash table
 
91
 */
 
92
 
 
93
struct item {
 
94
  char        *key;  /*!< Pointeur to string */
 
95
  mei_flag_t   type; /*!< Constant, variable, function,... */
 
96
  data_t      *data; /*!< Data of the current bucket */
 
97
  struct item *next; /*!< Pointer to next element */
 
98
};
 
99
 
 
100
/*!
 
101
 * \brief Structure defining a hash table
 
102
 */
 
103
 
 
104
struct HashTable {
 
105
  int           n_inter; /*!< number of interpreters associated with
 
106
                           the current table of symbols */
 
107
  int           record;  /*!< number of buckets of the hash table*/
 
108
  int           length;  /*!< length of the hash table */
 
109
  struct item **table;   /*!< 'table' is a list of pointers on 'item' */
 
110
};
 
111
 
 
112
/*!
 
113
 * \brief Type definition for a hash table
 
114
 */
 
115
 
 
116
typedef struct HashTable hash_table_t;
 
117
 
 
118
 
 
119
/*============================================================================
 
120
 * Public function prototypes
 
121
 *============================================================================*/
 
122
 
 
123
/*----------------------------------------------------------------------------
 
124
 *  Fonction qui cree une table de hachage
 
125
 *----------------------------------------------------------------------------*/
 
126
 
 
127
 
 
128
void mei_hash_table_create(hash_table_t *const htable, const int modulo);
 
129
 
 
130
 
 
131
/*----------------------------------------------------------------------------
 
132
 *  Fonction qui initialise la table de hachage
 
133
 *----------------------------------------------------------------------------*/
 
134
 
 
135
 
 
136
void mei_hash_table_init(hash_table_t *htable);
 
137
 
 
138
 
 
139
void mei_hash_table_dump(hash_table_t *htable);
 
140
 
 
141
 
 
142
void mei_hash_table_item_print(struct item *item);
 
143
 
 
144
 
 
145
void mei_hash_table_free(hash_table_t *htable);
 
146
 
 
147
 
 
148
struct item * mei_hash_table_lookup(hash_table_t *htable, const char *key);
 
149
 
 
150
 
 
151
void mei_hash_table_insert(hash_table_t *const htable,
 
152
                           const char *const  key,
 
153
                           const mei_flag_t type,
 
154
                           const double value,
 
155
                           const func1_t func,
 
156
                           const func2_t f2,
 
157
                           const func3_t f3,
 
158
                           const func4_t f4);
 
159
 
 
160
 
 
161
struct item* mei_hash_table_find(hash_table_t *htable, const char *key);
 
162
 
 
163
/*----------------------------------------------------------------------------*/
 
164
 
 
165
#ifdef __cplusplus
 
166
}
 
167
#endif /* __cplusplus */
 
168
 
 
169
#endif /* __MEI_HASH_TABLE_H__ */
 
170