76#define st_dict_cast(dict) ((struct StDictNode*)(dict))
78#define st_dict_setk(dict, key) ((dict)->dictnode.str = (key))
80#define st_dict_getk(dict) ((dict)->dictnode.str)
82#define st_dict_datap(dict) (&(dict)->data)
84#define st_dict_ins(dict, node) \
85 ((void*)st_dictnode_ins(st_dict_cast(dict), st_dict_cast(node)))
87#define st_dict_find(dict, key) \
88 ((void*)st_dictnode_find(st_dict_cast(dict), (key)))
90#define st_dict_first(dict) \
91 ((void*)(st_dictnode_from(st_rb_first(&dict_cast(dict)->node, 0))))
93#define st_dict_next(dict) \
94 ((void*)(st_dictnode_from(st_rb_next(&dict_cast(dict)->node, 0))))
109#define st_dict_cast(dict) \
111 __typeof__(dict) _dict2 = (dict); \
113 _dict2 ? &_dict2->dictnode : NULL; \
126#define st_dict_setk(dict, key) \
128 __typeof__(dict) _dict = (dict); \
130 ST_ENSURE(_dict, ST_ERROR, null_param); \
131 _dict->dictnode.str = (key); \
145#define st_dict_getk(dict) \
147 __typeof__(dict) _dict = (dict); \
149 ST_ENSURE(_dict, ST_ERROR, null_param); \
150 _dict->dictnode.str; \
164#define st_dict_datap(dict) \
166 __typeof__(dict) _dict = (dict); \
168 ST_ENSURE(_dict, ST_ERROR, null_param); \
184#define st_dict_ins(dict, entry) \
186 __typeof__(dict) _dict = (dict); \
190 st_dict_cast(_dict), st_dict_cast(entry)), \
191 __typeof__(*dict), dictnode); \
206#define st_dict_find(dict, key) \
208 __typeof__(dict) _dict = (dict); \
211 st_dictnode_find(st_dict_cast(_dict), (key)), \
212 __typeof__(*dict), dictnode); \
229#define st_dict_first(dict) \
231 __typeof__(dict) _dict = (dict); \
235 st_rb_first(&dict_cast(_dict)->node, 0)), \
236 __typeof__(*dict), dictnode); \
253#define st_dict_next(dict) \
255 __typeof__(dict) _dict = (dict); \
258 st_dictnode_from(st_rb_next( \
259 &dict_cast(_dict)->node, ST_BST_INORDER)), \
260 __typeof__(*dict), dictnode); \
276#define ST_DICT(name, type) \
279 struct StDictNode dictnode; \
Basic arithmetic operations.
#define st_container_of(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition arith.h:91
struct StDictNode * st_dictnode_ins(struct StDictNode *root, struct StDictNode *entry)
Insert an entry into the dictionary.
struct StDictNode * st_dictnode_find(struct StDictNode *root, const char *str)
In a dictionary, find the entry with the given key.
static struct StDictNode * st_dictnode_from(struct StRbNode *ptr)
Cast a StRbNode member out to the containing StDictNode structure.
Definition dict.h:338
Dictionary node.
Definition dict.h:288
char * str
The key string.
Definition dict.h:301
struct StRbNode node
The red-black tree node.
Definition dict.h:294
Node of a red-black tree.