ucx/map.h

changeset 31
91ac86557290
parent 30
23bb65cbf7a4
child 38
35f67a8ef875
equal deleted inserted replaced
30:23bb65cbf7a4 31:91ac86557290
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 };
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);
38 void ucx_map_free(UcxMap *map); 48 void ucx_map_free(UcxMap *map);
39 49
40 int ucx_map_put(UcxMap *map, UcxKey key, void *data); 50 int ucx_map_put(UcxMap *map, UcxKey key, void *data);
47 57
48 UcxKey ucx_key(void *data, size_t len); 58 UcxKey ucx_key(void *data, size_t len);
49 59
50 int ucx_hash(char *data, size_t len); 60 int ucx_hash(char *data, size_t len);
51 61
62 UcxMapIterator ucx_map_iterator(UcxMap *map);
63
64 int ucx_map_iter_next(UcxMapIterator *i, void **elm);
65
52 #ifdef __cplusplus 66 #ifdef __cplusplus
53 } 67 }
54 #endif 68 #endif
55 69
56 #endif /* MAP_H */ 70 #endif /* MAP_H */

mercurial