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" olaf@20: olaf@2: #ifdef __cplusplus olaf@2: extern "C" { olaf@2: #endif olaf@2: olaf@20: typedef struct UcxMap UcxMap; olaf@20: typedef struct UcxKey UcxKey; olaf@20: typedef struct UcxMapElement UcxMapElement; olaf@2: olaf@20: struct UcxMap { olaf@20: 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@20: olaf@20: UcxMap *ucx_map_new(size_t size); 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@20: #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d) olaf@20: #define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, strlen(s)), d) olaf@20: #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length)) olaf@20: #define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 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@2: #ifdef __cplusplus olaf@2: } olaf@2: #endif olaf@2: olaf@2: #endif /* MAP_H */ olaf@2: