44 #include "Parser_dh.h"
47 static void Hash_dhInit_private (
Hash_dh h,
int s);
49 #define CUR_MARK_INIT -1
61 #define __FUNC__ "Hash_dhCreate"
63 Hash_dhCreate (
Hash_dh * h,
int size)
72 tmp->curMark = CUR_MARK_INIT + 1;
75 Hash_dhInit_private (*h, size);
80 #define __FUNC__ "Hash_dhDestroy"
84 START_FUNC_DH
if (h->data != NULL)
94 #define __FUNC__ "Hash_dhReset"
98 START_FUNC_DH h->count = 0;
103 #define __FUNC__ "Hash_dhInit_private"
105 Hash_dhInit_private (
Hash_dh h,
int s)
115 if ((size - s) < (.1 * size))
129 for (i = 0; i < size; ++i)
137 #define __FUNC__ "Hash_dhLookup"
139 Hash_dhLookup (
Hash_dh h,
int key)
141 START_FUNC_DH
int i, start;
142 int curMark = h->curMark;
147 HASH_1 (key, size, &start) for (i = 0; i < size; ++i)
150 HASH_2 (key, size, &tmp) idx = (start + i * tmp) % size;
151 if (data[idx].mark != curMark)
157 if (data[idx].key == key)
159 retval = &(data[idx].data);
164 END_FUNC_VAL (retval)}
172 #define __FUNC__ "Hash_dhInsert"
176 START_FUNC_DH
int i, start, size = h->size;
177 int curMark = h->curMark;
184 if (h->count == h->size)
186 SET_V_ERROR (
"hash table overflow; rehash need implementing!");
189 HASH_1 (key, size, &start) for (i = 0; i < size; ++i)
192 HASH_2 (key, size, &tmp) idx = (start + i * tmp) % size;
193 if (data[idx].mark < curMark)
196 data[idx].mark = curMark;
197 memcpy (&(data[idx].data), dataIN,
sizeof (
HashData));
204 #define __FUNC__ "Hash_dhPrint"
206 Hash_dhPrint (
Hash_dh h, FILE * fp)
208 START_FUNC_DH
int i, size = h->size;
209 int curMark = h->curMark;
213 fprintf (fp,
"\n--------------------------- hash table \n");
214 for (i = 0; i < size; ++i)
216 if (data[i].mark == curMark)
218 fprintf (fp,
"key = %2i; iData = %3i; fData = %g\n",
219 data[i].key, data[i].data.iData, data[i].data.fData);