Lines 114-119
Link Here
|
114 |
|
114 |
|
115 |
#endif |
115 |
#endif |
116 |
|
116 |
|
|
|
117 |
#if __STDC_VERSION__ <= 201710L |
117 |
#define bl_map_set(result, map, __key, __value) \ |
118 |
#define bl_map_set(result, map, __key, __value) \ |
118 |
{ \ |
119 |
{ \ |
119 |
int __hash_key; \ |
120 |
int __hash_key; \ |
Lines 193-198
Link Here
|
193 |
__hash_key = bl_map_rehash(__hash_key, (map)->map_size); \ |
194 |
__hash_key = bl_map_rehash(__hash_key, (map)->map_size); \ |
194 |
} \ |
195 |
} \ |
195 |
} |
196 |
} |
|
|
197 |
#else /* horrors of C23 and macro expansions */ |
198 |
#define bl_map_set(result, map, __key, __value) \ |
199 |
{ \ |
200 |
int __hash_key; \ |
201 |
u_int __count; \ |
202 |
\ |
203 |
result = 0; \ |
204 |
\ |
205 |
if ((map)->map_size == (map)->filled_size + MAP_MARGIN_SIZE) { \ |
206 |
/* \ |
207 |
* Expanding map by DEFAULT_MAP_SIZE \ |
208 |
*/ \ |
209 |
\ |
210 |
u_int __new_size; \ |
211 |
void* __new; \ |
212 |
\ |
213 |
__new_size = (map)->map_size + DEFAULT_MAP_SIZE; \ |
214 |
\ |
215 |
bl_map_dump_size((map)->map_size, __new_size); \ |
216 |
\ |
217 |
if ((__new = calloc(__new_size, sizeof(*(map)->pairs)))) { \ |
218 |
void* __old; \ |
219 |
\ |
220 |
__old = (map)->pairs; \ |
221 |
\ |
222 |
if ((int (*)(int, u_int))(map)->hash_func == bl_map_hash_int || \ |
223 |
(int (*)(int, u_int))(map)->hash_func == bl_map_hash_int_fast) { \ |
224 |
if (__new_size & (__new_size - 1)) { \ |
225 |
/* XXX int (*)() should be int (*)(key_type, u_int) */ \ |
226 |
(map)->hash_func = (typeof((map)->hash_func))bl_map_hash_int; \ |
227 |
} else { \ |
228 |
/* __new_size == 2^n */ \ |
229 |
/* XXX int (*)() should be int (*)(key_type, u_int) */ \ |
230 |
(map)->hash_func = (typeof((map)->hash_func))bl_map_hash_int_fast; \ |
231 |
} \ |
232 |
} \ |
233 |
\ |
234 |
/* reconstruct (map)->pairs since map_size is changed. */ \ |
235 |
for (__count = 0; __count < (map)->map_size; __count++) { \ |
236 |
if ((map)->pairs[__count].is_filled) { \ |
237 |
void *dst; \ |
238 |
\ |
239 |
__hash_key = (*(map)->hash_func)((map)->pairs[__count].key, __new_size); \ |
240 |
\ |
241 |
(map)->pairs = __new; \ |
242 |
while ((map)->pairs[__hash_key].is_filled) { \ |
243 |
__hash_key = bl_map_rehash(__hash_key, __new_size); \ |
244 |
} \ |
245 |
\ |
246 |
dst = &(map)->pairs[__hash_key]; \ |
247 |
(map)->pairs = __old; \ |
248 |
memcpy(dst, &(map)->pairs[__count], sizeof(*(map)->pairs)); \ |
249 |
} \ |
250 |
} \ |
251 |
\ |
252 |
free(__old); \ |
253 |
(map)->pairs = __new; \ |
254 |
(map)->map_size = __new_size; \ |
255 |
} \ |
256 |
} \ |
257 |
\ |
258 |
__hash_key = (*(map)->hash_func)(__key, (map)->map_size); \ |
259 |
for (__count = 0; __count < (map)->map_size; __count++) { \ |
260 |
if (!(map)->pairs[__hash_key].is_filled) { \ |
261 |
(map)->pairs[__hash_key].key = __key; \ |
262 |
(map)->pairs[__hash_key].value = __value; \ |
263 |
(map)->pairs[__hash_key].is_filled = 1; \ |
264 |
(map)->filled_size++; \ |
265 |
\ |
266 |
free((map)->pairs_array); \ |
267 |
(map)->pairs_array = NULL; \ |
268 |
\ |
269 |
result = 1; \ |
270 |
\ |
271 |
break; \ |
272 |
} \ |
273 |
\ |
274 |
__hash_key = bl_map_rehash(__hash_key, (map)->map_size); \ |
275 |
} \ |
276 |
} |
277 |
#endif |
196 |
|
278 |
|
197 |
#define __bl_map_erase_simple(result, map, __key) \ |
279 |
#define __bl_map_erase_simple(result, map, __key) \ |
198 |
int __hash_key; \ |
280 |
int __hash_key; \ |