KEYS: Improve /proc/keys
[linux-2.6.git] / include / linux / btree-type.h
blob9a1147ef8563bec13ba46195657945b10866f922
1 #define __BTREE_TP(pfx, type, sfx) pfx ## type ## sfx
2 #define _BTREE_TP(pfx, type, sfx) __BTREE_TP(pfx, type, sfx)
3 #define BTREE_TP(pfx) _BTREE_TP(pfx, BTREE_TYPE_SUFFIX,)
4 #define BTREE_FN(name) BTREE_TP(btree_ ## name)
5 #define BTREE_TYPE_HEAD BTREE_TP(struct btree_head)
6 #define VISITOR_FN BTREE_TP(visitor)
7 #define VISITOR_FN_T _BTREE_TP(visitor, BTREE_TYPE_SUFFIX, _t)
9 BTREE_TYPE_HEAD {
10 struct btree_head h;
13 static inline void BTREE_FN(init_mempool)(BTREE_TYPE_HEAD *head,
14 mempool_t *mempool)
16 btree_init_mempool(&head->h, mempool);
19 static inline int BTREE_FN(init)(BTREE_TYPE_HEAD *head)
21 return btree_init(&head->h);
24 static inline void BTREE_FN(destroy)(BTREE_TYPE_HEAD *head)
26 btree_destroy(&head->h);
29 static inline int BTREE_FN(merge)(BTREE_TYPE_HEAD *target,
30 BTREE_TYPE_HEAD *victim,
31 gfp_t gfp)
33 return btree_merge(&target->h, &victim->h, BTREE_TYPE_GEO, gfp);
36 #if (BITS_PER_LONG > BTREE_TYPE_BITS)
37 static inline void *BTREE_FN(lookup)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
39 unsigned long _key = key;
40 return btree_lookup(&head->h, BTREE_TYPE_GEO, &_key);
43 static inline int BTREE_FN(insert)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
44 void *val, gfp_t gfp)
46 unsigned long _key = key;
47 return btree_insert(&head->h, BTREE_TYPE_GEO, &_key, val, gfp);
50 static inline int BTREE_FN(update)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
51 void *val)
53 unsigned long _key = key;
54 return btree_update(&head->h, BTREE_TYPE_GEO, &_key, val);
57 static inline void *BTREE_FN(remove)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
59 unsigned long _key = key;
60 return btree_remove(&head->h, BTREE_TYPE_GEO, &_key);
63 static inline void *BTREE_FN(last)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
65 unsigned long _key;
66 void *val = btree_last(&head->h, BTREE_TYPE_GEO, &_key);
67 if (val)
68 *key = _key;
69 return val;
72 static inline void *BTREE_FN(get_prev)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
74 unsigned long _key = *key;
75 void *val = btree_get_prev(&head->h, BTREE_TYPE_GEO, &_key);
76 if (val)
77 *key = _key;
78 return val;
80 #else
81 static inline void *BTREE_FN(lookup)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
83 return btree_lookup(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key);
86 static inline int BTREE_FN(insert)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
87 void *val, gfp_t gfp)
89 return btree_insert(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key,
90 val, gfp);
93 static inline int BTREE_FN(update)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
94 void *val)
96 return btree_update(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key, val);
99 static inline void *BTREE_FN(remove)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
101 return btree_remove(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key);
104 static inline void *BTREE_FN(last)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
106 return btree_last(&head->h, BTREE_TYPE_GEO, (unsigned long *)key);
109 static inline void *BTREE_FN(get_prev)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
111 return btree_get_prev(&head->h, BTREE_TYPE_GEO, (unsigned long *)key);
113 #endif
115 void VISITOR_FN(void *elem, unsigned long opaque, unsigned long *key,
116 size_t index, void *__func);
118 typedef void (*VISITOR_FN_T)(void *elem, unsigned long opaque,
119 BTREE_KEYTYPE key, size_t index);
121 static inline size_t BTREE_FN(visitor)(BTREE_TYPE_HEAD *head,
122 unsigned long opaque,
123 VISITOR_FN_T func2)
125 return btree_visitor(&head->h, BTREE_TYPE_GEO, opaque,
126 visitorl, func2);
129 static inline size_t BTREE_FN(grim_visitor)(BTREE_TYPE_HEAD *head,
130 unsigned long opaque,
131 VISITOR_FN_T func2)
133 return btree_grim_visitor(&head->h, BTREE_TYPE_GEO, opaque,
134 visitorl, func2);
137 #undef VISITOR_FN
138 #undef VISITOR_FN_T
139 #undef __BTREE_TP
140 #undef _BTREE_TP
141 #undef BTREE_TP
142 #undef BTREE_FN
143 #undef BTREE_TYPE_HEAD
144 #undef BTREE_TYPE_SUFFIX
145 #undef BTREE_TYPE_GEO
146 #undef BTREE_KEYTYPE
147 #undef BTREE_TYPE_BITS