65 #define UCX_MAP_FOREACH(key,value,iter) \ |
65 #define UCX_MAP_FOREACH(key,value,iter) \ |
66 for(UcxKey key;ucx_map_iter_next(&iter,&key, (void**)&value);) |
66 for(UcxKey key;ucx_map_iter_next(&iter,&key, (void**)&value);) |
67 |
67 |
68 /** Type for the UCX map. @see UcxMap */ |
68 /** Type for the UCX map. @see UcxMap */ |
69 typedef struct UcxMap UcxMap; |
69 typedef struct UcxMap UcxMap; |
|
70 |
70 /** Type for a key of an UcxMap. @see UcxKey */ |
71 /** Type for a key of an UcxMap. @see UcxKey */ |
71 typedef struct UcxKey UcxKey; |
72 typedef struct UcxKey UcxKey; |
|
73 |
72 /** Type for an element of an UcxMap. @see UcxMapElement */ |
74 /** Type for an element of an UcxMap. @see UcxMapElement */ |
73 typedef struct UcxMapElement UcxMapElement; |
75 typedef struct UcxMapElement UcxMapElement; |
|
76 |
74 /** Type for an iterator over an UcxMap. @see UcxMapIterator */ |
77 /** Type for an iterator over an UcxMap. @see UcxMapIterator */ |
75 typedef struct UcxMapIterator UcxMapIterator; |
78 typedef struct UcxMapIterator UcxMapIterator; |
76 |
79 |
77 /** Structure for the UCX map. */ |
80 /** Structure for the UCX map. */ |
78 struct UcxMap { |
81 struct UcxMap { |
98 |
101 |
99 /** Structure for an element of an UcxMap. */ |
102 /** Structure for an element of an UcxMap. */ |
100 struct UcxMapElement { |
103 struct UcxMapElement { |
101 /** The value data. */ |
104 /** The value data. */ |
102 void *data; |
105 void *data; |
|
106 |
103 /** A pointer to the next element in the current list. */ |
107 /** A pointer to the next element in the current list. */ |
104 UcxMapElement *next; |
108 UcxMapElement *next; |
|
109 |
105 /** The corresponding key. */ |
110 /** The corresponding key. */ |
106 UcxKey key; |
111 UcxKey key; |
107 }; |
112 }; |
108 |
113 |
109 /** Structure for an iterator over an UcxMap. */ |
114 /** Structure for an iterator over an UcxMap. */ |
110 struct UcxMapIterator { |
115 struct UcxMapIterator { |
111 /** The map to iterate over. */ |
116 /** The map to iterate over. */ |
112 UcxMap *map; |
117 UcxMap *map; |
|
118 |
113 /** The current map element. */ |
119 /** The current map element. */ |
114 UcxMapElement *cur; |
120 UcxMapElement *cur; |
|
121 |
115 /** |
122 /** |
116 * The current index of the element list array. |
123 * The current index of the element list array. |
117 * <b>Attention: </b> this is <b>NOT</b> the element index! Do <b>NOT</b> |
124 * <b>Attention: </b> this is <b>NOT</b> the element index! Do <b>NOT</b> |
118 * manually iterate over the map by increasing this index. Use |
125 * manually iterate over the map by increasing this index. Use |
119 * ucx_map_iter_next(). |
126 * ucx_map_iter_next(). |
233 * @return 0 on success, non-zero value on failure |
240 * @return 0 on success, non-zero value on failure |
234 * @see ucx_map_put() |
241 * @see ucx_map_put() |
235 */ |
242 */ |
236 #define ucx_map_sstr_put(map, key, value) \ |
243 #define ucx_map_sstr_put(map, key, value) \ |
237 ucx_map_put(map, ucx_key(key.ptr, key.length), (void*)value) |
244 ucx_map_put(map, ucx_key(key.ptr, key.length), (void*)value) |
|
245 |
238 /** |
246 /** |
239 * Shorthand for putting data with a C string key into the map. |
247 * Shorthand for putting data with a C string key into the map. |
240 * @param map the map |
248 * @param map the map |
241 * @param key the key |
249 * @param key the key |
242 * @param value the value |
250 * @param value the value |
243 * @return 0 on success, non-zero value on failure |
251 * @return 0 on success, non-zero value on failure |
244 * @see ucx_map_put() |
252 * @see ucx_map_put() |
245 */ |
253 */ |
246 #define ucx_map_cstr_put(map, key, value) \ |
254 #define ucx_map_cstr_put(map, key, value) \ |
247 ucx_map_put(map, ucx_key((void*)key, strlen(key)), (void*)value) |
255 ucx_map_put(map, ucx_key((void*)key, strlen(key)), (void*)value) |
|
256 |
248 /** |
257 /** |
249 * Shorthand for putting data with an integer key into the map. |
258 * Shorthand for putting data with an integer key into the map. |
250 * @param map the map |
259 * @param map the map |
251 * @param key the key |
260 * @param key the key |
252 * @param value the value |
261 * @param value the value |
254 * @see ucx_map_put() |
263 * @see ucx_map_put() |
255 */ |
264 */ |
256 #define ucx_map_int_put(map, key, value) \ |
265 #define ucx_map_int_put(map, key, value) \ |
257 ucx_map_put(map, ucx_key((void*)&key, sizeof(key)), (void*)value) |
266 ucx_map_put(map, ucx_key((void*)&key, sizeof(key)), (void*)value) |
258 |
267 |
259 |
|
260 /** |
268 /** |
261 * Shorthand for getting data from the map with a sstr_t key. |
269 * Shorthand for getting data from the map with a sstr_t key. |
262 * @param map the map |
270 * @param map the map |
263 * @param key the key |
271 * @param key the key |
264 * @return the value |
272 * @return the value |
265 * @see ucx_map_get() |
273 * @see ucx_map_get() |
266 */ |
274 */ |
267 #define ucx_map_sstr_get(map, key) \ |
275 #define ucx_map_sstr_get(map, key) \ |
268 ucx_map_get(map, ucx_key(key.ptr, key.length)) |
276 ucx_map_get(map, ucx_key(key.ptr, key.length)) |
|
277 |
269 /** |
278 /** |
270 * Shorthand for getting data from the map with a C string key. |
279 * Shorthand for getting data from the map with a C string key. |
271 * @param map the map |
280 * @param map the map |
272 * @param key the key |
281 * @param key the key |
273 * @return the value |
282 * @return the value |
274 * @see ucx_map_get() |
283 * @see ucx_map_get() |
275 */ |
284 */ |
276 #define ucx_map_cstr_get(map, key) \ |
285 #define ucx_map_cstr_get(map, key) \ |
277 ucx_map_get(map, ucx_key((void*)key, strlen(key))) |
286 ucx_map_get(map, ucx_key((void*)key, strlen(key))) |
|
287 |
278 /** |
288 /** |
279 * Shorthand for getting data from the map with an integer key. |
289 * Shorthand for getting data from the map with an integer key. |
280 * @param map the map |
290 * @param map the map |
281 * @param key the key |
291 * @param key the key |
282 * @return the value |
292 * @return the value |
283 * @see ucx_map_get() |
293 * @see ucx_map_get() |
284 */ |
294 */ |
285 #define ucx_map_int_get(map, key) \ |
295 #define ucx_map_int_get(map, key) \ |
286 ucx_map_get(map, ucx_key((void*)&key, sizeof(int))) |
296 ucx_map_get(map, ucx_key((void*)&key, sizeof(int))) |
|
297 |
287 /** |
298 /** |
288 * Shorthand for removing data from the map with a sstr_t key. |
299 * Shorthand for removing data from the map with a sstr_t key. |
289 * @param map the map |
300 * @param map the map |
290 * @param key the key |
301 * @param key the key |
291 * @return the removed value |
302 * @return the removed value |
292 * @see ucx_map_remove() |
303 * @see ucx_map_remove() |
293 */ |
304 */ |
294 #define ucx_map_sstr_remove(map, key) \ |
305 #define ucx_map_sstr_remove(map, key) \ |
295 ucx_map_remove(map, ucx_key(key.ptr, key.length)) |
306 ucx_map_remove(map, ucx_key(key.ptr, key.length)) |
|
307 |
296 /** |
308 /** |
297 * Shorthand for removing data from the map with a C string key. |
309 * Shorthand for removing data from the map with a C string key. |
298 * @param map the map |
310 * @param map the map |
299 * @param key the key |
311 * @param key the key |
300 * @return the removed value |
312 * @return the removed value |
301 * @see ucx_map_remove() |
313 * @see ucx_map_remove() |
302 */ |
314 */ |
303 #define ucx_map_cstr_remove(map, key) \ |
315 #define ucx_map_cstr_remove(map, key) \ |
304 ucx_map_remove(map, ucx_key((void*)key, strlen(key))) |
316 ucx_map_remove(map, ucx_key((void*)key, strlen(key))) |
|
317 |
305 /** |
318 /** |
306 * Shorthand for removing data from the map with an integer key. |
319 * Shorthand for removing data from the map with an integer key. |
307 * @param map the map |
320 * @param map the map |
308 * @param key the key |
321 * @param key the key |
309 * @return the removed value |
322 * @return the removed value |