diff -r 27c7511c0e34 -r 280250e45ba6 src/server/ucx/map.h --- a/src/server/ucx/map.h Thu May 24 12:51:52 2012 +0200 +++ b/src/server/ucx/map.h Fri May 25 18:16:24 2012 +0200 @@ -12,12 +12,16 @@ extern "C" { #endif -typedef struct UcxMap UcxMap; -typedef struct UcxKey UcxKey; -typedef struct UcxMapElement UcxMapElement; +#define UCX_MAP_FOREACH(type,elm,map,iter) \ + for(type elm;ucx_map_iter_next(&iter,(void*)&elm)==0;) + +typedef struct UcxMap UcxMap; +typedef struct UcxKey UcxKey; +typedef struct UcxMapElement UcxMapElement; +typedef struct UcxMapIterator UcxMapIterator; struct UcxMap { - UcxMapElement *map; + UcxMapElement **map; size_t size; }; @@ -33,21 +37,32 @@ UcxKey key; }; +struct UcxMapIterator { + UcxMap *map; + UcxMapElement *cur; + int index; +}; + UcxMap *ucx_map_new(size_t size); +void ucx_map_free(UcxMap *map); int ucx_map_put(UcxMap *map, UcxKey key, void *data); void* ucx_map_get(UcxMap *map, UcxKey key); #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d) -#define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, strlen(s)), d) +#define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, 1+strlen(s)), d) #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length)) -#define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, strlen(s))) +#define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 1+strlen(s))) UcxKey ucx_key(void *data, size_t len); int ucx_hash(char *data, size_t len); +UcxMapIterator ucx_map_iterator(UcxMap *map); + +int ucx_map_iter_next(UcxMapIterator *i, void **elm); + #ifdef __cplusplus } #endif