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