comparison src/hash.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents 8eaf7971accc
children f955c73f5258
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
87 87
88 return h; 88 return h;
89 } 89 }
90 90
91 static int 91 static int
92 string_eq (CONST void *st1v, CONST void *st2v) 92 string_eq (CONST void *st1, CONST void *st2)
93 { 93 {
94 CONST char *st1 = (CONST char *)st1v;
95 CONST char *st2 = (CONST char *)st2v;
96
97 if (!st1) 94 if (!st1)
98 return (st2)?0:1; 95 return st2 ? 0 : 1;
99 else if (!st2) 96 else if (!st2)
100 return 0; 97 return 0;
101 else 98 else
102 return !strcmp (st1, st2); 99 return !strcmp ( (CONST char *) st1, (CONST char *) st2);
103 } 100 }
104 101
105 102
106 static unsigned int 103 static unsigned int
107 prime_size (unsigned int size) 104 prime_size (unsigned int size)
179 } 176 }
180 177
181 c_hashtable 178 c_hashtable
182 make_hashtable (unsigned int hsize) 179 make_hashtable (unsigned int hsize)
183 { 180 {
184 c_hashtable res = (c_hashtable) xmalloc (sizeof (struct _C_hashtable)); 181 c_hashtable res = xnew_and_zero (struct _C_hashtable);
185 memset (res, 0, sizeof (struct _C_hashtable));
186 res->size = prime_size ((13 * hsize) / 10); 182 res->size = prime_size ((13 * hsize) / 10);
187 res->harray = (hentry *) xmalloc (sizeof (hentry) * res->size); 183 res->harray = xnew_array (hentry, res->size);
188 #ifdef emacs 184 #ifdef emacs
189 res->elisp_table = Qnil; 185 res->elisp_table = Qnil;
190 #endif 186 #endif
191 clrhash (res); 187 clrhash (res);
192 return res; 188 return res;
195 c_hashtable 191 c_hashtable
196 make_general_hashtable (unsigned int hsize, 192 make_general_hashtable (unsigned int hsize,
197 unsigned long (*hash_function) (CONST void *), 193 unsigned long (*hash_function) (CONST void *),
198 int (*test_function) (CONST void *, CONST void *)) 194 int (*test_function) (CONST void *, CONST void *))
199 { 195 {
200 c_hashtable res = (c_hashtable) xmalloc (sizeof (struct _C_hashtable)); 196 c_hashtable res = xnew_and_zero (struct _C_hashtable);
201 memset (res, 0, sizeof (struct _C_hashtable));
202 res->size = prime_size ((13 * hsize) / 10); 197 res->size = prime_size ((13 * hsize) / 10);
203 res->harray = (hentry *) xmalloc (sizeof (hentry) * res->size); 198 res->harray = xnew_array (hentry, res->size);
204 res->hash_function = hash_function; 199 res->hash_function = hash_function;
205 res->test_function = test_function; 200 res->test_function = test_function;
206 #ifdef emacs 201 #ifdef emacs
207 res->elisp_table = Qnil; 202 res->elisp_table = Qnil;
208 #endif 203 #endif
251 dest->harray = (hentry *) 246 dest->harray = (hentry *)
252 elisp_hvector_malloc (sizeof (hentry) * dest->size, 247 elisp_hvector_malloc (sizeof (hentry) * dest->size,
253 dest->elisp_table); 248 dest->elisp_table);
254 else 249 else
255 #endif 250 #endif
256 dest->harray = (hentry *) xmalloc (sizeof (hentry) * dest->size); 251 dest->harray = xnew_array (hentry, dest->size);
257 } 252 }
258 dest->fullness = src->fullness; 253 dest->fullness = src->fullness;
259 dest->zero_entry = src->zero_entry; 254 dest->zero_entry = src->zero_entry;
260 dest->zero_set = src->zero_set; 255 dest->zero_set = src->zero_set;
261 dest->hash_function = src->hash_function; 256 dest->hash_function = src->hash_function;