Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[cris-mirror.git] / include / linux / btree-type.h
blobfb34a52c788b22a433e294c27878364e894583bd
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #define __BTREE_TP(pfx, type, sfx) pfx ## type ## sfx
3 #define _BTREE_TP(pfx, type, sfx) __BTREE_TP(pfx, type, sfx)
4 #define BTREE_TP(pfx) _BTREE_TP(pfx, BTREE_TYPE_SUFFIX,)
5 #define BTREE_FN(name) BTREE_TP(btree_ ## name)
6 #define BTREE_TYPE_HEAD BTREE_TP(struct btree_head)
7 #define VISITOR_FN BTREE_TP(visitor)
8 #define VISITOR_FN_T _BTREE_TP(visitor, BTREE_TYPE_SUFFIX, _t)
10 BTREE_TYPE_HEAD {
11 struct btree_head h;
14 static inline void BTREE_FN(init_mempool)(BTREE_TYPE_HEAD *head,
15 mempool_t *mempool)
17 btree_init_mempool(&head->h, mempool);
20 static inline int BTREE_FN(init)(BTREE_TYPE_HEAD *head)
22 return btree_init(&head->h);
25 static inline void BTREE_FN(destroy)(BTREE_TYPE_HEAD *head)
27 btree_destroy(&head->h);
30 static inline int BTREE_FN(merge)(BTREE_TYPE_HEAD *target,
31 BTREE_TYPE_HEAD *victim,
32 gfp_t gfp)
34 return btree_merge(&target->h, &victim->h, BTREE_TYPE_GEO, gfp);
37 #if (BITS_PER_LONG > BTREE_TYPE_BITS)
38 static inline void *BTREE_FN(lookup)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
40 unsigned long _key = key;
41 return btree_lookup(&head->h, BTREE_TYPE_GEO, &_key);
44 static inline int BTREE_FN(insert)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
45 void *val, gfp_t gfp)
47 unsigned long _key = key;
48 return btree_insert(&head->h, BTREE_TYPE_GEO, &_key, val, gfp);
51 static inline int BTREE_FN(update)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
52 void *val)
54 unsigned long _key = key;
55 return btree_update(&head->h, BTREE_TYPE_GEO, &_key, val);
58 static inline void *BTREE_FN(remove)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
60 unsigned long _key = key;
61 return btree_remove(&head->h, BTREE_TYPE_GEO, &_key);
64 static inline void *BTREE_FN(last)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
66 unsigned long _key;
67 void *val = btree_last(&head->h, BTREE_TYPE_GEO, &_key);
68 if (val)
69 *key = _key;
70 return val;
73 static inline void *BTREE_FN(get_prev)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
75 unsigned long _key = *key;
76 void *val = btree_get_prev(&head->h, BTREE_TYPE_GEO, &_key);
77 if (val)
78 *key = _key;
79 return val;
81 #else
82 static inline void *BTREE_FN(lookup)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
84 return btree_lookup(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key);
87 static inline int BTREE_FN(insert)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
88 void *val, gfp_t gfp)
90 return btree_insert(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key,
91 val, gfp);
94 static inline int BTREE_FN(update)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
95 void *val)
97 return btree_update(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key, val);
100 static inline void *BTREE_FN(remove)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
102 return btree_remove(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key);
105 static inline void *BTREE_FN(last)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
107 return btree_last(&head->h, BTREE_TYPE_GEO, (unsigned long *)key);
110 static inline void *BTREE_FN(get_prev)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
112 return btree_get_prev(&head->h, BTREE_TYPE_GEO, (unsigned long *)key);
114 #endif
116 void VISITOR_FN(void *elem, unsigned long opaque, unsigned long *key,
117 size_t index, void *__func);
119 typedef void (*VISITOR_FN_T)(void *elem, unsigned long opaque,
120 BTREE_KEYTYPE key, size_t index);
122 static inline size_t BTREE_FN(visitor)(BTREE_TYPE_HEAD *head,
123 unsigned long opaque,
124 VISITOR_FN_T func2)
126 return btree_visitor(&head->h, BTREE_TYPE_GEO, opaque,
127 visitorl, func2);
130 static inline size_t BTREE_FN(grim_visitor)(BTREE_TYPE_HEAD *head,
131 unsigned long opaque,
132 VISITOR_FN_T func2)
134 return btree_grim_visitor(&head->h, BTREE_TYPE_GEO, opaque,
135 visitorl, func2);
138 #undef VISITOR_FN
139 #undef VISITOR_FN_T
140 #undef __BTREE_TP
141 #undef _BTREE_TP
142 #undef BTREE_TP
143 #undef BTREE_FN
144 #undef BTREE_TYPE_HEAD
145 #undef BTREE_TYPE_SUFFIX
146 #undef BTREE_TYPE_GEO
147 #undef BTREE_KEYTYPE
148 #undef BTREE_TYPE_BITS