1.1 --- a/ucx/map.h Sat Dec 31 22:48:28 2011 +0100 1.2 +++ b/ucx/map.h Thu Jan 05 14:53:54 2012 +0100 1.3 @@ -5,12 +5,48 @@ 1.4 #ifndef MAP_H 1.5 #define MAP_H 1.6 1.7 +#include "ucx.h" 1.8 +#include "string.h" 1.9 + 1.10 #ifdef __cplusplus 1.11 extern "C" { 1.12 #endif 1.13 1.14 +typedef struct UcxMap UcxMap; 1.15 +typedef struct UcxKey UcxKey; 1.16 +typedef struct UcxMapElement UcxMapElement; 1.17 1.18 +struct UcxMap { 1.19 + UcxMapElement *map; 1.20 + size_t size; 1.21 +}; 1.22 1.23 +struct UcxKey { 1.24 + void *data; 1.25 + size_t len; 1.26 + int hash; 1.27 +}; 1.28 + 1.29 +struct UcxMapElement { 1.30 + void *data; 1.31 + UcxMapElement *next; 1.32 + UcxKey key; 1.33 +}; 1.34 + 1.35 + 1.36 +UcxMap *ucx_map_new(size_t size); 1.37 + 1.38 +int ucx_map_put(UcxMap *map, UcxKey key, void *data); 1.39 +void* ucx_map_get(UcxMap *map, UcxKey key); 1.40 + 1.41 +#define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d) 1.42 +#define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, strlen(s)), d) 1.43 +#define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length)) 1.44 +#define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, strlen(s))) 1.45 + 1.46 +UcxKey ucx_key(void *data, size_t len); 1.47 + 1.48 +int ucx_hash(char *data, size_t len); 1.49 1.50 #ifdef __cplusplus 1.51 }