diff -r 2e7050c3a18e -r db7d9860dbbd ucx/map.h --- a/ucx/map.h Sat Dec 31 22:48:28 2011 +0100 +++ b/ucx/map.h Thu Jan 05 14:53:54 2012 +0100 @@ -5,12 +5,48 @@ #ifndef MAP_H #define MAP_H +#include "ucx.h" +#include "string.h" + #ifdef __cplusplus extern "C" { #endif +typedef struct UcxMap UcxMap; +typedef struct UcxKey UcxKey; +typedef struct UcxMapElement UcxMapElement; +struct UcxMap { + UcxMapElement *map; + size_t size; +}; +struct UcxKey { + void *data; + size_t len; + int hash; +}; + +struct UcxMapElement { + void *data; + UcxMapElement *next; + UcxKey key; +}; + + +UcxMap *ucx_map_new(size_t size); + +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_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))) + +UcxKey ucx_key(void *data, size_t len); + +int ucx_hash(char *data, size_t len); #ifdef __cplusplus }