src/server/ucx/map.h

Mon, 23 Jul 2012 15:13:19 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 23 Jul 2012 15:13:19 +0200
changeset 32
ebba53de8b18
parent 31
280250e45ba6
child 36
450d2d5f4735
permissions
-rw-r--r--

added solaris 10 support

15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 *
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 */
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 #ifndef MAP_H
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 #define MAP_H
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 #include "ucx.h"
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 #include "string.h"
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 #ifdef __cplusplus
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 extern "C" {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 #endif
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
15 #define UCX_MAP_FOREACH(type,elm,map,iter) \
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
16 for(type elm;ucx_map_iter_next(&iter,(void*)&elm)==0;)
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
17
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
18 typedef struct UcxMap UcxMap;
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
19 typedef struct UcxKey UcxKey;
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
20 typedef struct UcxMapElement UcxMapElement;
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
21 typedef struct UcxMapIterator UcxMapIterator;
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 struct UcxMap {
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
24 UcxMapElement **map;
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 size_t size;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 };
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28 struct UcxKey {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 void *data;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 size_t len;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 int hash;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 };
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 struct UcxMapElement {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 void *data;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 UcxMapElement *next;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 UcxKey key;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 };
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
40 struct UcxMapIterator {
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
41 UcxMap *map;
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
42 UcxMapElement *cur;
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
43 int index;
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
44 };
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
45
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 UcxMap *ucx_map_new(size_t size);
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
48 void ucx_map_free(UcxMap *map);
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 int ucx_map_put(UcxMap *map, UcxKey key, void *data);
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 void* ucx_map_get(UcxMap *map, UcxKey key);
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 #define ucx_map_sstr_put(m, s, d) ucx_map_put(m, ucx_key(s.ptr, s.length), d)
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
54 #define ucx_map_cstr_put(m, s, d) ucx_map_put(m, ucx_key(s, 1+strlen(s)), d)
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 #define ucx_map_sstr_get(m, s) ucx_map_get(m, ucx_key(s.ptr, s.length))
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
56 #define ucx_map_cstr_get(m, s) ucx_map_get(m, ucx_key(s, 1+strlen(s)))
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 UcxKey ucx_key(void *data, size_t len);
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 int ucx_hash(char *data, size_t len);
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
31
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
62 UcxMapIterator ucx_map_iterator(UcxMap *map);
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
63
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
64 int ucx_map_iter_next(UcxMapIterator *i, void **elm);
280250e45ba6 updated ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
65
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 #ifdef __cplusplus
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 }
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 #endif
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 #endif /* MAP_H */
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71

mercurial