• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef PTRMAP_H
2 #define PTRMAP_H
3 
4 struct ptrmap;
5 
6 #define DECLARE_PTRMAP(name, ktype, vtype)				\
7 	struct name ## _pair { ktype key; vtype val; };			\
8 	struct name { struct name ## _pair block[1]; };			\
9 	static inline							\
10 	void name##_add(struct name **map, ktype k, vtype v) {		\
11 		__ptrmap_add((struct ptrmap**)map, k, v);		\
12 	}								\
13 	static inline							\
14 	void name##_update(struct name **map, ktype k, vtype v) {	\
15 		__ptrmap_update((struct ptrmap**)map, k, v);		\
16 	}								\
17 	static inline							\
18 	vtype name##_lookup(struct name *map, ktype k) {		\
19 		vtype val = __ptrmap_lookup((struct ptrmap*)map, k);	\
20 		return val;						\
21 	}								\
22 
23 /* ptrmap.c */
24 void __ptrmap_add(struct ptrmap **mapp, void *key, void *val);
25 void __ptrmap_update(struct ptrmap **mapp, void *key, void *val);
26 void *__ptrmap_lookup(struct ptrmap *map, void *key);
27 
28 #endif
29