0001
0002 #define __BTREE_TP(pfx, type, sfx) pfx ## type ## sfx
0003 #define _BTREE_TP(pfx, type, sfx) __BTREE_TP(pfx, type, sfx)
0004 #define BTREE_TP(pfx) _BTREE_TP(pfx, BTREE_TYPE_SUFFIX,)
0005 #define BTREE_FN(name) BTREE_TP(btree_ ## name)
0006 #define BTREE_TYPE_HEAD BTREE_TP(struct btree_head)
0007 #define VISITOR_FN BTREE_TP(visitor)
0008 #define VISITOR_FN_T _BTREE_TP(visitor, BTREE_TYPE_SUFFIX, _t)
0009
0010 BTREE_TYPE_HEAD {
0011 struct btree_head h;
0012 };
0013
0014 static inline void BTREE_FN(init_mempool)(BTREE_TYPE_HEAD *head,
0015 mempool_t *mempool)
0016 {
0017 btree_init_mempool(&head->h, mempool);
0018 }
0019
0020 static inline int BTREE_FN(init)(BTREE_TYPE_HEAD *head)
0021 {
0022 return btree_init(&head->h);
0023 }
0024
0025 static inline void BTREE_FN(destroy)(BTREE_TYPE_HEAD *head)
0026 {
0027 btree_destroy(&head->h);
0028 }
0029
0030 static inline int BTREE_FN(merge)(BTREE_TYPE_HEAD *target,
0031 BTREE_TYPE_HEAD *victim,
0032 gfp_t gfp)
0033 {
0034 return btree_merge(&target->h, &victim->h, BTREE_TYPE_GEO, gfp);
0035 }
0036
0037 #if (BITS_PER_LONG > BTREE_TYPE_BITS)
0038 static inline void *BTREE_FN(lookup)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
0039 {
0040 unsigned long _key = key;
0041 return btree_lookup(&head->h, BTREE_TYPE_GEO, &_key);
0042 }
0043
0044 static inline int BTREE_FN(insert)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
0045 void *val, gfp_t gfp)
0046 {
0047 unsigned long _key = key;
0048 return btree_insert(&head->h, BTREE_TYPE_GEO, &_key, val, gfp);
0049 }
0050
0051 static inline int BTREE_FN(update)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
0052 void *val)
0053 {
0054 unsigned long _key = key;
0055 return btree_update(&head->h, BTREE_TYPE_GEO, &_key, val);
0056 }
0057
0058 static inline void *BTREE_FN(remove)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
0059 {
0060 unsigned long _key = key;
0061 return btree_remove(&head->h, BTREE_TYPE_GEO, &_key);
0062 }
0063
0064 static inline void *BTREE_FN(last)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
0065 {
0066 unsigned long _key;
0067 void *val = btree_last(&head->h, BTREE_TYPE_GEO, &_key);
0068 if (val)
0069 *key = _key;
0070 return val;
0071 }
0072
0073 static inline void *BTREE_FN(get_prev)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
0074 {
0075 unsigned long _key = *key;
0076 void *val = btree_get_prev(&head->h, BTREE_TYPE_GEO, &_key);
0077 if (val)
0078 *key = _key;
0079 return val;
0080 }
0081 #else
0082 static inline void *BTREE_FN(lookup)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
0083 {
0084 return btree_lookup(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key);
0085 }
0086
0087 static inline int BTREE_FN(insert)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
0088 void *val, gfp_t gfp)
0089 {
0090 return btree_insert(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key,
0091 val, gfp);
0092 }
0093
0094 static inline int BTREE_FN(update)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key,
0095 void *val)
0096 {
0097 return btree_update(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key, val);
0098 }
0099
0100 static inline void *BTREE_FN(remove)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key)
0101 {
0102 return btree_remove(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key);
0103 }
0104
0105 static inline void *BTREE_FN(last)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
0106 {
0107 return btree_last(&head->h, BTREE_TYPE_GEO, (unsigned long *)key);
0108 }
0109
0110 static inline void *BTREE_FN(get_prev)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key)
0111 {
0112 return btree_get_prev(&head->h, BTREE_TYPE_GEO, (unsigned long *)key);
0113 }
0114 #endif
0115
0116 void VISITOR_FN(void *elem, unsigned long opaque, unsigned long *key,
0117 size_t index, void *__func);
0118
0119 typedef void (*VISITOR_FN_T)(void *elem, unsigned long opaque,
0120 BTREE_KEYTYPE key, size_t index);
0121
0122 static inline size_t BTREE_FN(visitor)(BTREE_TYPE_HEAD *head,
0123 unsigned long opaque,
0124 VISITOR_FN_T func2)
0125 {
0126 return btree_visitor(&head->h, BTREE_TYPE_GEO, opaque,
0127 visitorl, func2);
0128 }
0129
0130 static inline size_t BTREE_FN(grim_visitor)(BTREE_TYPE_HEAD *head,
0131 unsigned long opaque,
0132 VISITOR_FN_T func2)
0133 {
0134 return btree_grim_visitor(&head->h, BTREE_TYPE_GEO, opaque,
0135 visitorl, func2);
0136 }
0137
0138 #undef VISITOR_FN
0139 #undef VISITOR_FN_T
0140 #undef __BTREE_TP
0141 #undef _BTREE_TP
0142 #undef BTREE_TP
0143 #undef BTREE_FN
0144 #undef BTREE_TYPE_HEAD
0145 #undef BTREE_TYPE_SUFFIX
0146 #undef BTREE_TYPE_GEO
0147 #undef BTREE_KEYTYPE
0148 #undef BTREE_TYPE_BITS