Freeciv-3.3
Loading...
Searching...
No Matches
spechash.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14/* spechashes: "specific genhash".
15 *
16 * This file is used to implement a "specific" genhash.
17 * That is, a (sometimes) type-checked genhash. (Or at least a
18 * genhash with related functions with distinctly typed parameters.)
19 *
20 * Before including this file, you must define the following:
21 * SPECHASH_TAG - this tag will be used to form names for functions etc.
22 * SPECHASH_IKEY_TYPE - the typed genhash will use this type as key.
23 * (genhash internal usage). You may omit this setting defining
24 * SPECHASH_INT_KEY_TYPE, SPECHASH_ENUM_KEY_TYPE,
25 * SPECHASH_ASTR_KEY_TYPE, or SPECHASH_CSTR_KEY_TYPE, by convenience
26 * for integer, enumerators, or strings.
27 * SPECHASH_IDATA_TYPE - the typed genhash will use this type as data.
28 * (genhash internal usage). You may omit this setting defining
29 * SPECHASH_INT_DATA_TYPE, SPECHASH_ENUM_DATA_TYPE,
30 * SPECHASH_ASTR_DATA_TYPE, or SPECHASH_CSTR_DATA_TYPE, by convenience
31 * for integers, enumerators, or strings.
32 * You may also define:
33 * SPECHASH_UKEY_TYPE - the typed genhash will use this as key.
34 * (external user usage, see SPECHASH_UKEY_TO_IKEY and
35 * SPECHASH_IKEY_TO_UKEY converters).
36 * SPECHASH_UDATA_TYPE - the typed genhash will use this type as data.
37 * (external user usage, see SPECHASH_IDATA_TO_UDATA and
38 * SPECHASH_UDATA_TO_IDATA converters).
39 * SPECHASH_IKEY_VAL - The default hash function.
40 * SPECHASH_IKEY_COMP - The default hash key comparator function.
41 * SPECHASH_IKEY_COPY - The default key copy function.
42 * SPECHASH_IKEY_FREE - The default key free function.
43 * SPECHASH_IDATA_COMP - The default data comparator function.
44 * SPECHASH_IDATA_COPY - The default data copy function.
45 * SPECHASH_IDATA_FREE - The default data free function.
46 * SPECHASH_UKEY_TO_IKEY - A function or macro to convert a key to
47 * pointer.
48 * SPECHASH_IKEY_TO_UKEY - A function or macro to convert a pointer to
49 * key.
50 * SPECHASH_IDATA_TO_UDATA - A function or macro to convert a data to
51 * pointer.
52 * SPECHASH_UDATA_TO_IDATA - A function or macro to convert a pointer
53 * to data.
54 * SPECHASH_VPTR_TO_IKEY - A function or macro to convert void pointer
55 * to key.
56 * SPECHASH_VPTR_TO_IDATA - A function or macro to convert void pointer
57 * to data.
58 * At the end of this file, these (and other defines) are undef-ed.
59 *
60 * Assuming SPECHASH_TAG were 'foo', SPECHASH_IKEY_TYPE were 'key_t', and
61 * SPECHASH_IDATA_TYPE were 'data_t'.
62 * including this file would provide a struct definition for:
63 * struct foo_hash;
64 * struct foo_hash_iter;
65 *
66 * function typedefs:
67 * typedef genhash_val_t (*foo_hash_key_val_fn_t) (const key_t);
68 * typedef bool (*foo_hash_key_comp_fn_t) (const key_t, const key_t);
69 * typedef key_t (*foo_hash_key_copy_fn_t) (const key_t);
70 * typedef void (*foo_hash_key_free_fn_t) (key_t);
71 * typedef bool (*foo_hash_data_comp_fn_t) (const data_t, const data_t);
72 * typedef data_t (*foo_hash_data_copy_fn_t) (const data_t);
73 * typedef void (*foo_hash_data_free_fn_t) (data_t);
74 *
75 * and prototypes for the following functions:
76 * struct foo_hash *foo_hash_new(void);
77 * struct foo_hash *foo_hash_new_full(foo_hash_key_val_fn_t key_val,
78 * foo_hash_key_comp_fn_t key_comp,
79 * foo_hash_key_copy_fn_t key_copy,
80 * foo_hash_key_free_fn_t key_free,
81 * foo_hash_data_copy_fn_t data_val,
82 * foo_hash_data_free_fn_t data_free);
83 * struct foo_hash *foo_hash_new_nentries(size_t nentries);
84 * struct foo_hash *
85 * foo_hash_new_nentries_full(foo_hash_key_val_fn_t key_val,
86 * foo_hash_key_comp_fn_t key_comp,
87 * foo_hash_key_copy_fn_t key_copy,
88 * foo_hash_key_free_fn_t key_free,
89 * foo_hash_data_copy_fn_t data_val,
90 * foo_hash_data_free_fn_t data_free,
91 * size_t nentries);
92 * void foo_hash_destroy(struct foo_hash *phash);
93 * bool foo_hash_set_no_shrink(struct foo_hash *phash, bool no_shrink);
94 * size_t foo_hash_size(const struct foo_hash *phash);
95 * size_t foo_hash_capacity(const struct foo_hash *phash);
96 * struct foo_hash *foo_hash_copy(const struct foo_hash *phash);
97 * void foo_hash_clear(struct foo_hash *phash);
98 * bool foo_hash_insert(struct foo_hash *phash, const key_t key,
99 * const data_t data);
100 * bool foo_hash_replace(struct foo_hash *phash, const key_t key,
101 * const data_t data);
102 * bool foo_hash_replace_full(struct foo_hash *phash, const key_t key,
103 * const data_t data, key_t *old_pkey,
104 * data_t *old_pdata);
105 * bool foo_hash_lookup(const struct foo_hash *phash, const key_t key,
106 * data_t *pdata);
107 * bool foo_hash_remove(struct foo_hash *phash, const key_t key);
108 * bool foo_hash_remove_full(struct foo_hash *phash, const key_t key,
109 * key_t *deleted_pkey, data_t *deleted_pdata);
110 *
111 * bool foo_hashes_are_equal(const struct foo_hash *phash1,
112 * const struct foo_hash *phash2);
113 * bool foo_hashes_are_equal_full(const struct foo_hash *phash1,
114 * const struct foo_hash *phash2,
115 * foo_hash_data_comp_fn_t data_comp_func);
116 *
117 * size_t foo_hash_iter_sizeof(void);
118 * struct iterator *foo_hash_iter_init(struct foo_hash_iter *iter,
119 * const struct foo_hash *phash);
120 * struct iterator *foo_hash_key_iter_init(struct foo_hash_iter *iter,
121 * const struct foo_hash *phash);
122 * struct iterator *foo_hash_value_init(struct foo_hash_iter *iter,
123 * const struct foo_hash *phash);
124 *
125 * You should also define yourself (this file cannot do this for you):
126 * #define foo_hash_data_iterate(phash, data) \
127 * TYPED_HASH_DATA_ITERATE(data_t, phash, data)
128 * #define foo_hash_data_iterate_end HASH_DATA_ITERATE_END
129 *
130 * #define foo_hash_keys_iterate(phash, key) \
131 * TYPED_HASH_KEYS_ITERATE(key_t, phash, key)
132 * #define foo_hash_keys_iterate_end HASH_KEYS_ITERATE_END
133 *
134 * #define foo_hash_iterate(phash, key, data) \
135 * TYPED_HASH_ITERATE(key_t, data_t, phash, key, data)
136 * #define foo_hash_iterate_end HASH_ITERATE_END
137 *
138 * Note this is not protected against multiple inclusions; this is so that
139 * you can have multiple different speclists. For each speclist, this file
140 * should be included _once_, inside a .h file which _is_ itself protected
141 * against multiple inclusions. */
142
143#ifdef __cplusplus
144extern "C" {
145#endif /* __cplusplus */
146
147/* utility */
148#include "genhash.h"
149#include "iterator.h"
150#include "support.h"
151
152/* Pre-defined cases for convenience. */
153#ifdef SPECHASH_INT_KEY_TYPE
154#undef SPECHASH_INT_KEY_TYPE
155#define SPECHASH_UKEY_TYPE int
156#define SPECHASH_IKEY_TYPE void *
157#define SPECHASH_IKEY_TO_UKEY FC_PTR_TO_INT
158#define SPECHASH_UKEY_TO_IKEY FC_INT_TO_PTR
159#define SPECHASH_IKEY_VAL nullptr
160#define SPECHASH_IKEY_COMP nullptr
161#define SPECHASH_IKEY_COPY nullptr
162#define SPECHASH_IKEY_FREE nullptr
163#endif/* SPECHASH_INT_KEY_TYPE */
164#ifdef SPECHASH_INT_DATA_TYPE
165#undef SPECHASH_INT_DATA_TYPE
166#define SPECHASH_UDATA_TYPE int
167#define SPECHASH_IDATA_TYPE void *
168#define SPECHASH_IDATA_TO_UDATA FC_PTR_TO_INT
169#define SPECHASH_UDATA_TO_IDATA FC_INT_TO_PTR
170#define SPECHASH_IDATA_COMP nullptr
171#define SPECHASH_IDATA_COPY nullptr
172#define SPECHASH_IDATA_FREE nullptr
173#endif/* SPECHASH_INT_DATA_TYPE */
174#ifdef SPECHASH_ENUM_KEY_TYPE
175#define SPECHASH_UKEY_TYPE enum SPECHASH_ENUM_KEY_TYPE
176#define SPECHASH_IKEY_TYPE void *
177#define SPECHASH_IKEY_TO_UKEY FC_PTR_TO_INT
178#define SPECHASH_UKEY_TO_IKEY FC_INT_TO_PTR
179#define SPECHASH_IKEY_VAL nullptr
180#define SPECHASH_IKEY_COMP nullptr
181#define SPECHASH_IKEY_COPY nullptr
182#define SPECHASH_IKEY_FREE nullptr
183#endif/* SPECHASH_ENUM_KEY_TYPE */
184#ifdef SPECHASH_ENUM_DATA_TYPE
185#define SPECHASH_UDATA_TYPE enum SPECHASH_ENUM_DATA_TYPE
186#define SPECHASH_IDATA_TYPE void *
187#define SPECHASH_IDATA_TO_UDATA FC_PTR_TO_INT
188#define SPECHASH_UDATA_TO_IDATA FC_INT_TO_PTR
189#define SPECHASH_IDATA_COMP nullptr
190#define SPECHASH_IDATA_COPY nullptr
191#define SPECHASH_IDATA_FREE nullptr
192#endif/* SPECHASH_ENUM_DATA_TYPE */
193#ifdef SPECHASH_ASTR_KEY_TYPE
194#undef SPECHASH_ASTR_KEY_TYPE
195#define SPECHASH_IKEY_TYPE char *
196#define SPECHASH_IKEY_VAL genhash_str_val_func
197#define SPECHASH_IKEY_COMP genhash_str_comp_func
198#define SPECHASH_IKEY_COPY genhash_str_copy_func
199#define SPECHASH_IKEY_FREE genhash_str_free_func
200#endif /* SPECHASH_ASTR_KEY_TYPE */
201#ifdef SPECHASH_ASTR_DATA_TYPE
202#undef SPECHASH_ASTR_DATA_TYPE
203#define SPECHASH_IDATA_TYPE char *
204#define SPECHASH_IDATA_COMP genhash_str_comp_func
205#define SPECHASH_IDATA_COPY genhash_str_copy_func
206#define SPECHASH_IDATA_FREE genhash_str_free_func
207#endif /* SPECHASH_ASTR_DATA_TYPE */
208#ifdef SPECHASH_CSTR_KEY_TYPE
209#undef SPECHASH_CSTR_KEY_TYPE
210#define SPECHASH_IKEY_TYPE char *
211#define SPECHASH_IKEY_VAL genhash_str_val_func
212#define SPECHASH_IKEY_COMP genhash_str_comp_func
213#define SPECHASH_IKEY_COPY nullptr
214#define SPECHASH_IKEY_FREE nullptr
215#endif /* SPECHASH_CSTR_KEY_TYPE */
216#ifdef SPECHASH_CSTR_DATA_TYPE
217#undef SPECHASH_CSTR_DATA_TYPE
218#define SPECHASH_IDATA_TYPE char *
219#define SPECHASH_IDATA_COMP genhash_str_comp_func
220#define SPECHASH_IDATA_COPY nullptr
221#define SPECHASH_IDATA_FREE nullptr
222#endif /* SPECHASH_CSTR_DATA_TYPE */
223
224#ifndef SPECHASH_VPTR_TO_IKEY
225#define SPECHASH_VPTR_TO_IKEY(p) ((SPECHASH_IKEY_TYPE)(p))
226#endif
227
228#ifndef SPECHASH_VPTR_TO_IDATA
229#define SPECHASH_VPTR_TO_IDATA(p) ((SPECHASH_IDATA_TYPE)(p))
230#endif
231
232#ifndef SPECHASH_TAG
233#error Must define a SPECHASH_TAG to use this header
234#endif
235#ifndef SPECHASH_IKEY_TYPE
236#error Must define a SPECHASH_IKEY_TYPE to use this header
237#endif
238#ifndef SPECHASH_UKEY_TYPE
239#define SPECHASH_UKEY_TYPE SPECHASH_IKEY_TYPE
240#endif
241#ifndef SPECHASH_IDATA_TYPE
242#error Must define a SPECHASH_IDATA_TYPE to use this header
243#endif
244#ifndef SPECHASH_UDATA_TYPE
245#define SPECHASH_UDATA_TYPE SPECHASH_IDATA_TYPE
246#endif
247
248/* Default functions. */
249#ifndef SPECHASH_IKEY_VAL
250#define SPECHASH_IKEY_VAL nullptr
251#endif
252#ifndef SPECHASH_IKEY_COMP
253#define SPECHASH_IKEY_COMP nullptr
254#endif
255#ifndef SPECHASH_IKEY_COPY
256#define SPECHASH_IKEY_COPY nullptr
257#endif
258#ifndef SPECHASH_IKEY_FREE
259#define SPECHASH_IKEY_FREE nullptr
260#endif
261#ifndef SPECHASH_IDATA_COMP
262#define SPECHASH_IDATA_COMP nullptr
263#endif
264#ifndef SPECHASH_IDATA_COPY
265#define SPECHASH_IDATA_COPY nullptr
266#endif
267#ifndef SPECHASH_IDATA_FREE
268#define SPECHASH_IDATA_FREE nullptr
269#endif
270
271/* Other functions or macros. */
272#ifndef SPECHASH_UKEY_TO_IKEY
273#define SPECHASH_UKEY_TO_IKEY(ukey) ((SPECHASH_IKEY_TYPE) (ukey))
274#endif
275#ifndef SPECHASH_IKEY_TO_UKEY
276#define SPECHASH_IKEY_TO_UKEY(ikey) ((SPECHASH_UKEY_TYPE) (ikey))
277#endif
278#ifndef SPECHASH_UDATA_TO_IDATA
279#define SPECHASH_UDATA_TO_IDATA(udata) ((SPECHASH_IDATA_TYPE) (udata))
280#endif
281#ifndef SPECHASH_IDATA_TO_UDATA
282#define SPECHASH_IDATA_TO_UDATA(idata) ((SPECHASH_UDATA_TYPE) (idata))
283#endif
284
285#define SPECHASH_PASTE_(x, y) x ## y
286#define SPECHASH_PASTE(x, y) SPECHASH_PASTE_(x, y)
287
288#define SPECHASH_HASH struct SPECHASH_PASTE(SPECHASH_TAG, _hash)
289#define SPECHASH_ITER struct SPECHASH_PASTE(SPECHASH_TAG, _hash_iter)
290#define SPECHASH_FOO(suffix) SPECHASH_PASTE(SPECHASH_TAG, suffix)
291
292/* Dummy type. Actually a genhash, and not defined anywhere. */
294
295/* Dummy type. Actually a genhash_iter, and not defined anywhere. */
297
298/* Function related typedefs. */
302 const SPECHASH_IKEY_TYPE);
303typedef SPECHASH_IKEY_TYPE
306typedef bool
308 const SPECHASH_IDATA_TYPE);
312
315static inline SPECHASH_HASH *
318 key_comp_func,
320 key_copy_func,
322 key_free_func,
324 data_copy_func,
326 data_free_func)
328static inline SPECHASH_HASH *
331static inline SPECHASH_HASH *
333 key_val_func,
335 key_comp_func,
337 key_copy_func,
339 key_free_func,
341 data_copy_func,
343 data_free_func, size_t nentries)
345
346/************************************************************************/
358
359/************************************************************************/
362static inline SPECHASH_HASH *
365 key_comp_func,
367 key_copy_func,
369 key_free_func,
371 data_copy_func,
373 data_free_func)
374{
375 return ((SPECHASH_HASH *)
376 genhash_new_full((genhash_val_fn_t) key_val_func,
377 (genhash_comp_fn_t) key_comp_func,
378 (genhash_copy_fn_t) key_copy_func,
379 (genhash_free_fn_t) key_free_func,
380 (genhash_copy_fn_t) data_copy_func,
381 (genhash_free_fn_t) data_free_func));
382}
383
384/************************************************************************/
387static inline SPECHASH_HASH *
398
399/************************************************************************/
402static inline SPECHASH_HASH *
404 key_val_func,
406 key_comp_func,
408 key_copy_func,
410 key_free_func,
412 data_copy_func,
414 data_free_func, size_t nentries)
415{
416 return ((SPECHASH_HASH *)
418 (genhash_comp_fn_t) key_comp_func,
419 (genhash_copy_fn_t) key_copy_func,
420 (genhash_free_fn_t) key_free_func,
421 (genhash_copy_fn_t) data_copy_func,
422 (genhash_free_fn_t) data_free_func,
423 nentries));
424}
425
426/************************************************************************/
430{
431 genhash_destroy((struct genhash *) tthis);
432}
433
434/************************************************************************/
438 bool no_shrink)
439{
440 return genhash_set_no_shrink((struct genhash *) tthis, no_shrink);
441}
442
443/************************************************************************/
446static inline size_t SPECHASH_FOO(_hash_size) (const SPECHASH_HASH *tthis)
447{
448 return genhash_size((const struct genhash *) tthis);
449}
450
451/************************************************************************/
454static inline size_t
456{
457 return genhash_capacity((const struct genhash *) tthis);
458}
459
460/************************************************************************/
463static inline SPECHASH_HASH *
466
467static inline SPECHASH_HASH *
469{
470 return (SPECHASH_HASH *) genhash_copy((const struct genhash *) tthis);
471}
472
473/************************************************************************/
477{
478 genhash_clear((struct genhash *) tthis);
479}
480
481/************************************************************************/
485static inline bool
494
495/************************************************************************/
499static inline bool
508
509/************************************************************************/
513static inline bool
535
536/************************************************************************/
539static inline bool
543{
544 void *data_ptr;
545 bool ret = genhash_lookup((const struct genhash *) tthis,
547
548 if (pudata != nullptr) {
550 }
551
552 return ret;
553}
554
555/************************************************************************/
558static inline bool
565
566/************************************************************************/
569static inline bool
589
590/************************************************************************/
593static inline bool
603
604/************************************************************************/
607static inline bool
614
615/************************************************************************/
618static inline size_t SPECHASH_FOO(_hash_iter_sizeof) (void)
619{
620 return genhash_iter_sizeof();
621}
622
623/************************************************************************/
626static inline struct iterator *
628 const SPECHASH_HASH *tthis)
629{
630 return genhash_iter_init((struct genhash_iter *) iter,
631 (const struct genhash *) tthis);
632}
633
634/************************************************************************/
637static inline struct iterator *
639 const SPECHASH_HASH *tthis)
640{
641 return genhash_key_iter_init((struct genhash_iter *) iter,
642 (const struct genhash *) tthis);
643}
644
645/************************************************************************/
648static inline struct iterator *
650 const SPECHASH_HASH *tthis)
651{
652 return genhash_value_iter_init((struct genhash_iter *) iter,
653 (const struct genhash *) tthis);
654}
655
656#undef SPECHASH_TAG
657#undef SPECHASH_IKEY_TYPE
658#undef SPECHASH_UKEY_TYPE
659#undef SPECHASH_IDATA_TYPE
660#undef SPECHASH_UDATA_TYPE
661#undef SPECHASH_IKEY_VAL
662#undef SPECHASH_IKEY_COMP
663#undef SPECHASH_IKEY_COPY
664#undef SPECHASH_IKEY_FREE
665#undef SPECHASH_IDATA_COMP
666#undef SPECHASH_IDATA_COPY
667#undef SPECHASH_IDATA_FREE
668#undef SPECHASH_UKEY_TO_IKEY
669#undef SPECHASH_IKEY_TO_UKEY
670#undef SPECHASH_UDATA_TO_IDATA
671#undef SPECHASH_IDATA_TO_UDATA
672#undef SPECHASH_VPTR_TO_IKEY
673#undef SPECHASH_VPTR_TO_IDATA
674#undef SPECHASH_PASTE_
675#undef SPECHASH_PASTE
676#undef SPECHASH_HASH
677#undef SPECHASH_ITER
678#undef SPECHASH_FOO
679#ifdef SPECHASH_ENUM_KEY_TYPE
680#undef SPECHASH_ENUM_KEY_TYPE
681#endif
682#ifdef SPECHASH_ENUM_DATA_TYPE
683#undef SPECHASH_ENUM_DATA_TYPE
684#endif
685
686
687/* Base macros that the users can specialize. */
688#ifndef FC__SPECHASH_H /* Defines this only once, no multiple inclusions. */
689#define FC__SPECHASH_H
690
691/* Spechash value iterator.
692 *
693 * TYPE_data - The real type of the data in the genhash.
694 * ARG_ht - The genhash to iterate.
695 * NAME_data - The name of the data iterator (defined inside the macro). */
696#define TYPED_HASH_DATA_ITERATE(TYPE_data, ARG_ht, NAME_data) \
697 generic_iterate(struct genhash_iter, TYPE_data, NAME_data, \
698 genhash_iter_sizeof, genhash_value_iter_init, \
699 (const struct genhash *) (ARG_ht))
700
701/* Balance for above: */
702#define HASH_DATA_ITERATE_END generic_iterate_end
703
704/* Spechash key iterator.
705 *
706 * TYPE_key - The real type of the key in the genhash.
707 * ARG_ht - The genhash to iterate.
708 * NAME_key - The name of the key iterator (defined inside the macro). */
709#define TYPED_HASH_KEYS_ITERATE(TYPE_key, ARG_ht, NAME_key) \
710 generic_iterate(struct genhash_iter, TYPE_key, NAME_key, \
711 genhash_iter_sizeof, genhash_key_iter_init, \
712 (const struct genhash *) (ARG_ht))
713
714/* Balance for above: */
715#define HASH_KEYS_ITERATE_END \
716 } \
717} while (FALSE);
718
719/* Spechash key and values iterator.
720 *
721 * TYPE_key - The real type of the key in the genhash.
722 * TYPE_data - The real type of the key in the genhash.
723 * ARG_ht - The genhash to iterate.
724 * NAME_key - The name of the key iterator (defined inside the macro).
725 * NAME_data - The name of the data iterator (defined inside the macro). */
726#define TYPED_HASH_ITERATE(TYPE_key, TYPE_data, ARG_ht, NAME_key, NAME_data)\
727 genhash_iterate((const struct genhash *) (ARG_ht), MY_iter) { \
728 TYPE_key NAME_key = (TYPE_key) genhash_iter_key(MY_iter); \
729 TYPE_data NAME_data = (TYPE_data) genhash_iter_value(MY_iter);
730
731/* Balance for above: */
732#define HASH_ITERATE_END \
733 } genhash_iterate_end;
734
735#endif /* FC__SPECHASH_H */
736
737/* This is after #endif FC__SPECHASH_H on purpose.
738 extern "C" portion begins well before latter part of the header
739 is guarded against multiple inclusions. */
740#ifdef __cplusplus
741}
742#endif /* __cplusplus */
char * incite_cost
Definition comments.c:76
struct iterator * genhash_iter_init(struct genhash_iter *iter, const struct genhash *pgenhash)
Definition genhash.c:873
struct genhash * genhash_new_full(genhash_val_fn_t key_val_func, genhash_comp_fn_t key_comp_func, genhash_copy_fn_t key_copy_func, genhash_free_fn_t key_free_func, genhash_copy_fn_t data_copy_func, genhash_free_fn_t data_free_func)
Definition genhash.c:265
bool genhash_insert(struct genhash *pgenhash, const void *key, const void *data)
Definition genhash.c:596
bool genhash_set_no_shrink(struct genhash *pgenhash, bool no_shrink)
Definition genhash.c:510
size_t genhash_size(const struct genhash *pgenhash)
Definition genhash.c:523
void genhash_destroy(struct genhash *pgenhash)
Definition genhash.c:290
size_t genhash_capacity(const struct genhash *pgenhash)
Definition genhash.c:531
void genhash_clear(struct genhash *pgenhash)
Definition genhash.c:576
struct iterator * genhash_value_iter_init(struct genhash_iter *iter, const struct genhash *pgenhash)
Definition genhash.c:891
size_t genhash_iter_sizeof(void)
Definition genhash.c:777
bool genhash_lookup(const struct genhash *pgenhash, const void *key, void **pdata)
Definition genhash.c:668
bool genhashes_are_equal_full(const struct genhash *pgenhash1, const struct genhash *pgenhash2, genhash_comp_fn_t data_comp_func)
Definition genhash.c:732
bool genhash_remove(struct genhash *pgenhash, const void *key)
Definition genhash.c:686
bool genhash_replace_full(struct genhash *pgenhash, const void *key, const void *data, void **old_pkey, void **old_pdata)
Definition genhash.c:637
struct iterator * genhash_key_iter_init(struct genhash_iter *iter, const struct genhash *pgenhash)
Definition genhash.c:882
bool genhash_replace(struct genhash *pgenhash, const void *key, const void *data)
Definition genhash.c:622
struct genhash * genhash_copy(const struct genhash *pgenhash)
Definition genhash.c:539
struct genhash * genhash_new_nentries_full(genhash_val_fn_t key_val_func, genhash_comp_fn_t key_comp_func, genhash_copy_fn_t key_copy_func, genhash_free_fn_t key_free_func, genhash_copy_fn_t data_copy_func, genhash_free_fn_t data_free_func, size_t nentries)
Definition genhash.c:233
bool genhash_remove_full(struct genhash *pgenhash, const void *key, void **deleted_pkey, void **deleted_pdata)
Definition genhash.c:698
genhash_val_t(* genhash_val_fn_t)(const void *)
Definition genhash.h:35
bool(* genhash_comp_fn_t)(const void *, const void *)
Definition genhash.h:36
void(* genhash_free_fn_t)(void *)
Definition genhash.h:38
void *(* genhash_copy_fn_t)(const void *)
Definition genhash.h:37
unsigned int genhash_val_t
Definition genhash.h:32
#define SPECHASH_IKEY_TYPE
#define SPECHASH_IDATA_TYPE
#define SPECHASH_IDATA_FREE
Definition spechash.h:268
static bool SPECHASH_FOO() _hash_remove_full(SPECHASH_HASH *tthis, const SPECHASH_UKEY_TYPE ukey, SPECHASH_UKEY_TYPE *deleted_pukey, SPECHASH_UDATA_TYPE *deleted_pudata)
Definition spechash.h:570
static size_t SPECHASH_FOO() _hash_capacity(const SPECHASH_HASH *tthis)
Definition spechash.h:455
#define SPECHASH_IDATA_TO_UDATA(idata)
Definition spechash.h:282
#define SPECHASH_UDATA_TYPE
Definition spechash.h:245
#define SPECHASH_FOO(suffix)
Definition spechash.h:290
#define SPECHASH_IDATA_COPY
Definition spechash.h:265
static bool SPECHASH_FOO() _hash_lookup(const SPECHASH_HASH *tthis, const SPECHASH_UKEY_TYPE ukey, SPECHASH_UDATA_TYPE *pudata)
Definition spechash.h:540
static size_t SPECHASH_FOO() _hash_size(const SPECHASH_HASH *tthis)
Definition spechash.h:446
static bool SPECHASH_FOO() _hash_insert(SPECHASH_HASH *tthis, const SPECHASH_UKEY_TYPE ukey, const SPECHASH_UDATA_TYPE udata)
Definition spechash.h:486
#define SPECHASH_IKEY_FREE
Definition spechash.h:259
static SPECHASH_HASH *SPECHASH_FOO() _hash_new_nentries_full(SPECHASH_FOO(_hash_key_val_fn_t) key_val_func, key_comp_func, key_copy_func, key_free_func, data_copy_func, data_free_func, size_t nentries) fc__warn_unused_result
Definition spechash.h:403
static bool SPECHASH_FOO() _hash_replace(SPECHASH_HASH *tthis, const SPECHASH_UKEY_TYPE ukey, const SPECHASH_UDATA_TYPE udata)
Definition spechash.h:500
#define SPECHASH_IKEY_VAL
Definition spechash.h:250
#define SPECHASH_IKEY_COMP
Definition spechash.h:253
static void SPECHASH_FOO() _hash_destroy(SPECHASH_HASH *tthis)
Definition spechash.h:429
static bool SPECHASH_FOO() _hashes_are_equal_full(const SPECHASH_HASH *phash1, const SPECHASH_HASH *phash2, data_comp_func)
Definition spechash.h:594
#define SPECHASH_UDATA_TO_IDATA(udata)
Definition spechash.h:279
static bool SPECHASH_FOO() _hashes_are_equal(const SPECHASH_HASH *phash1, const SPECHASH_HASH *phash2)
Definition spechash.h:608
static SPECHASH_HASH *SPECHASH_FOO() _hash_new_full(SPECHASH_FOO(_hash_key_val_fn_t) key_val_func, key_comp_func, key_copy_func, key_free_func, data_copy_func, data_free_func) fc__warn_unused_result
Definition spechash.h:363
static struct iterator *SPECHASH_FOO() _hash_iter_init(SPECHASH_ITER *iter, const SPECHASH_HASH *tthis)
Definition spechash.h:627
#define SPECHASH_IDATA_COMP
Definition spechash.h:262
static bool SPECHASH_FOO() _hash_remove(SPECHASH_HASH *tthis, const SPECHASH_UKEY_TYPE ukey)
Definition spechash.h:559
#define SPECHASH_UKEY_TYPE
Definition spechash.h:239
static struct iterator *SPECHASH_FOO() _hash_value_iter_init(SPECHASH_ITER *iter, const SPECHASH_HASH *tthis)
Definition spechash.h:649
static bool SPECHASH_FOO() _hash_replace_full(SPECHASH_HASH *tthis, const SPECHASH_UKEY_TYPE ukey, const SPECHASH_UDATA_TYPE udata, SPECHASH_UKEY_TYPE *old_pukey, SPECHASH_UDATA_TYPE *old_pudata)
Definition spechash.h:514
static void SPECHASH_FOO() _hash_clear(SPECHASH_HASH *tthis)
Definition spechash.h:476
static size_t SPECHASH_FOO() _hash_iter_sizeof(void)
Definition spechash.h:618
static SPECHASH_HASH *SPECHASH_FOO() _hash_new_nentries(size_t nentries) fc__warn_unused_result
Definition spechash.h:388
static struct iterator *SPECHASH_FOO() _hash_key_iter_init(SPECHASH_ITER *iter, const SPECHASH_HASH *tthis)
Definition spechash.h:638
static bool SPECHASH_FOO() _hash_set_no_shrink(SPECHASH_HASH *tthis, bool no_shrink)
Definition spechash.h:437
#define SPECHASH_VPTR_TO_IKEY(p)
Definition spechash.h:225
#define SPECHASH_IKEY_COPY
Definition spechash.h:256
#define SPECHASH_VPTR_TO_IDATA(p)
Definition spechash.h:229
#define SPECHASH_HASH
Definition spechash.h:288
#define SPECHASH_UKEY_TO_IKEY(ukey)
Definition spechash.h:273
static SPECHASH_HASH *SPECHASH_FOO() _hash_copy(const SPECHASH_HASH *tthis) fc__warn_unused_result
Definition spechash.h:468
#define SPECHASH_IKEY_TO_UKEY(ikey)
Definition spechash.h:276
static SPECHASH_HASH *SPECHASH_FOO() _hash_new(void) fc__warn_unused_result
Definition spechash.h:349
#define SPECHASH_ITER
Definition spechash.h:289
#define fc__warn_unused_result
Definition support.h:109
#define bool
Definition support.h:71