Fri, 24 Feb 2012 15:53:50 +0100
some fixes
olaf@2 | 1 | /* |
olaf@2 | 2 | * |
olaf@2 | 3 | */ |
olaf@2 | 4 | |
olaf@2 | 5 | #ifndef MAP_H |
olaf@2 | 6 | #define MAP_H |
olaf@2 | 7 | |
olaf@20 | 8 | #include "ucx.h" |
olaf@20 | 9 | #include "string.h" |
olaf@20 | 10 | |
olaf@2 | 11 | #ifdef __cplusplus |
olaf@2 | 12 | extern "C" { |
olaf@2 | 13 | #endif |
olaf@2 | 14 | |
olaf@20 | 15 | typedef struct UcxMap UcxMap; |
olaf@20 | 16 | typedef struct UcxKey UcxKey; |
olaf@20 | 17 | typedef struct UcxMapElement UcxMapElement; |
olaf@2 | 18 | |
olaf@20 | 19 | struct UcxMap { |
universe@29 | 20 | UcxMapElement **map; |
olaf@20 | 21 | size_t size; |
olaf@20 | 22 | }; |
olaf@2 | 23 | |
olaf@20 | 24 | struct UcxKey { |
olaf@20 | 25 | void *data; |
olaf@20 | 26 | size_t len; |
olaf@20 | 27 | int hash; |
olaf@20 | 28 | }; |
olaf@20 | 29 | |
olaf@20 | 30 | struct UcxMapElement { |
olaf@20 | 31 | void *data; |
olaf@20 | 32 | UcxMapElement *next; |
olaf@20 | 33 | UcxKey key; |
olaf@20 | 34 | }; |
olaf@20 | 35 | |
olaf@20 | 36 | |
olaf@20 | 37 | UcxMap *ucx_map_new(size_t size); |
universe@29 | 38 | void ucx_map_free(UcxMap *map); |
olaf@20 | 39 | |
olaf@20 | 40 | int ucx_map_put(UcxMap *map, UcxKey key, void *data); |
olaf@20 | 41 | void* ucx_map_get(UcxMap *map, UcxKey key); |
olaf@20 | 42 | |
olaf@30 | 43 | #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d) |
universe@29 | 44 | #define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, 1+strlen(s)), d) |
olaf@30 | 45 | #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length)) |
universe@29 | 46 | #define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 1+strlen(s))) |
olaf@20 | 47 | |
olaf@20 | 48 | UcxKey ucx_key(void *data, size_t len); |
olaf@20 | 49 | |
olaf@20 | 50 | int ucx_hash(char *data, size_t len); |
olaf@2 | 51 | |
olaf@2 | 52 | #ifdef __cplusplus |
olaf@2 | 53 | } |
olaf@2 | 54 | #endif |
olaf@2 | 55 | |
olaf@2 | 56 | #endif /* MAP_H */ |
olaf@2 | 57 |