olaf@2: /* olaf@2: * olaf@2: */ olaf@2: olaf@2: #ifndef MAP_H olaf@2: #define MAP_H olaf@2: olaf@20: #include "ucx.h" olaf@20: #include "string.h" universe@41: #include olaf@20: olaf@2: #ifdef __cplusplus olaf@2: extern "C" { olaf@2: #endif olaf@2: universe@41: #define UCX_MAP_FOREACH(elm,iter) \ universe@42: for(;ucx_map_iter_next(&iter,(void*)&elm)==0;) olaf@31: olaf@31: typedef struct UcxMap UcxMap; olaf@31: typedef struct UcxKey UcxKey; olaf@31: typedef struct UcxMapElement UcxMapElement; olaf@31: typedef struct UcxMapIterator UcxMapIterator; olaf@2: olaf@20: struct UcxMap { universe@29: UcxMapElement **map; olaf@20: size_t size; olaf@20: }; olaf@2: olaf@20: struct UcxKey { olaf@20: void *data; olaf@20: size_t len; olaf@20: int hash; olaf@20: }; olaf@20: olaf@20: struct UcxMapElement { olaf@20: void *data; olaf@20: UcxMapElement *next; olaf@20: UcxKey key; olaf@20: }; olaf@20: olaf@31: struct UcxMapIterator { olaf@31: UcxMap *map; olaf@31: UcxMapElement *cur; olaf@31: int index; olaf@31: }; olaf@31: olaf@20: olaf@20: UcxMap *ucx_map_new(size_t size); universe@29: void ucx_map_free(UcxMap *map); olaf@20: olaf@20: int ucx_map_put(UcxMap *map, UcxKey key, void *data); olaf@20: void* ucx_map_get(UcxMap *map, UcxKey key); olaf@20: olaf@30: #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d) universe@29: #define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, 1+strlen(s)), d) olaf@30: #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length)) universe@29: #define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 1+strlen(s))) olaf@20: olaf@20: UcxKey ucx_key(void *data, size_t len); olaf@20: olaf@20: int ucx_hash(char *data, size_t len); olaf@2: olaf@31: UcxMapIterator ucx_map_iterator(UcxMap *map); olaf@31: olaf@31: int ucx_map_iter_next(UcxMapIterator *i, void **elm); olaf@31: universe@42: /* use for string maps only, values are not encoded */ universe@42: int ucx_map_load(UcxMap *map, FILE *f); universe@42: int ucx_map_store(UcxMap *map, FILE *f); universe@42: universe@42: /* TODO: universe@42: int ucx_map_load_enc(UcxMap *map, FILE *f, copy_func decoder, void* decdata); universe@42: int ucx_map_store_enc(UcxMap *map, FILE *f, copy_func encoder, void* encdata); universe@42: */ universe@42: olaf@2: #ifdef __cplusplus olaf@2: } olaf@2: #endif olaf@2: olaf@2: #endif /* MAP_H */ olaf@2: