diff -r 4417619a9bbd -r 450d2d5f4735 src/server/ucx/map.h --- a/src/server/ucx/map.h Sat Aug 18 11:39:34 2012 +0200 +++ b/src/server/ucx/map.h Sat Oct 06 13:00:07 2012 +0200 @@ -7,22 +7,33 @@ #include "ucx.h" #include "string.h" +#include "mempool.h" +#include #ifdef __cplusplus extern "C" { #endif -#define UCX_MAP_FOREACH(type,elm,map,iter) \ - for(type elm;ucx_map_iter_next(&iter,(void*)&elm)==0;) +#define UCX_MAP_FOREACH(elm,iter) \ + for(;ucx_map_iter_next(&iter,(void*)&elm)==0;) typedef struct UcxMap UcxMap; typedef struct UcxKey UcxKey; typedef struct UcxMapElement UcxMapElement; typedef struct UcxMapIterator UcxMapIterator; +/* + * param 1: element + * param 2: additional data + * param 3: size of encoded data will be stored here + * returns encoded / decoded string or NULL on failure + */ +typedef void*(*ucx_map_coder)(void*,void*,size_t*); + struct UcxMap { UcxMapElement **map; size_t size; + size_t count; }; struct UcxKey { @@ -46,6 +57,10 @@ UcxMap *ucx_map_new(size_t size); void ucx_map_free(UcxMap *map); +/* you cannot clone maps with more than 390 mio entries */ +int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data); +UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data); +int ucx_map_rehash(UcxMap *map); int ucx_map_put(UcxMap *map, UcxKey key, void *data); void* ucx_map_get(UcxMap *map, UcxKey key); @@ -63,6 +78,16 @@ int ucx_map_iter_next(UcxMapIterator *i, void **elm); +/* use macros for string maps only, values are not encoded */ +#define ucx_map_load(map, f, alloc) ucx_map_load_enc(map, f, alloc, NULL, NULL) +#define ucx_map_store(map, f) ucx_map_store_enc(map, f, NULL, NULL) + +int ucx_map_load_enc(UcxMap *map, FILE *f, UcxAllocator allocator, + ucx_map_coder decoder, void* decdata); +/* encoders shall provide null terminated strings*/ +int ucx_map_store_enc(UcxMap *map, FILE *f, + ucx_map_coder encoder, void* encdata); + #ifdef __cplusplus } #endif