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