src/server/ucx/map.h

changeset 31
280250e45ba6
parent 15
cff9c4101dd7
child 36
450d2d5f4735
equal deleted inserted replaced
30:27c7511c0e34 31:280250e45ba6
10 10
11 #ifdef __cplusplus 11 #ifdef __cplusplus
12 extern "C" { 12 extern "C" {
13 #endif 13 #endif
14 14
15 typedef struct UcxMap UcxMap; 15 #define UCX_MAP_FOREACH(type,elm,map,iter) \
16 typedef struct UcxKey UcxKey; 16 for(type elm;ucx_map_iter_next(&iter,(void*)&elm)==0;)
17 typedef struct UcxMapElement UcxMapElement; 17
18 typedef struct UcxMap UcxMap;
19 typedef struct UcxKey UcxKey;
20 typedef struct UcxMapElement UcxMapElement;
21 typedef struct UcxMapIterator UcxMapIterator;
18 22
19 struct UcxMap { 23 struct UcxMap {
20 UcxMapElement *map; 24 UcxMapElement **map;
21 size_t size; 25 size_t size;
22 }; 26 };
23 27
24 struct UcxKey { 28 struct UcxKey {
25 void *data; 29 void *data;
31 void *data; 35 void *data;
32 UcxMapElement *next; 36 UcxMapElement *next;
33 UcxKey key; 37 UcxKey key;
34 }; 38 };
35 39
40 struct UcxMapIterator {
41 UcxMap *map;
42 UcxMapElement *cur;
43 int index;
44 };
45
36 46
37 UcxMap *ucx_map_new(size_t size); 47 UcxMap *ucx_map_new(size_t size);
48 void ucx_map_free(UcxMap *map);
38 49
39 int ucx_map_put(UcxMap *map, UcxKey key, void *data); 50 int ucx_map_put(UcxMap *map, UcxKey key, void *data);
40 void* ucx_map_get(UcxMap *map, UcxKey key); 51 void* ucx_map_get(UcxMap *map, UcxKey key);
41 52
42 #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d) 53 #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) 54 #define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, 1+strlen(s)), d)
44 #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length)) 55 #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))) 56 #define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 1+strlen(s)))
46 57
47 UcxKey ucx_key(void *data, size_t len); 58 UcxKey ucx_key(void *data, size_t len);
48 59
49 int ucx_hash(char *data, size_t len); 60 int ucx_hash(char *data, size_t len);
61
62 UcxMapIterator ucx_map_iterator(UcxMap *map);
63
64 int ucx_map_iter_next(UcxMapIterator *i, void **elm);
50 65
51 #ifdef __cplusplus 66 #ifdef __cplusplus
52 } 67 }
53 #endif 68 #endif
54 69

mercurial