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)
14 static inline void BTREE_FN(init_mempool
)(BTREE_TYPE_HEAD
*head
,
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
,
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
,
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
,
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
)
67 void *val
= btree_last(&head
->h
, BTREE_TYPE_GEO
, &_key
);
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
);
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
,
90 return btree_insert(&head
->h
, BTREE_TYPE_GEO
, (unsigned long *)&key
,
94 static inline int BTREE_FN(update
)(BTREE_TYPE_HEAD
*head
, BTREE_KEYTYPE key
,
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
);
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
,
126 return btree_visitor(&head
->h
, BTREE_TYPE_GEO
, opaque
,
130 static inline size_t BTREE_FN(grim_visitor
)(BTREE_TYPE_HEAD
*head
,
131 unsigned long opaque
,
134 return btree_grim_visitor(&head
->h
, BTREE_TYPE_GEO
, opaque
,
144 #undef BTREE_TYPE_HEAD
145 #undef BTREE_TYPE_SUFFIX
146 #undef BTREE_TYPE_GEO
148 #undef BTREE_TYPE_BITS