Joern Engel | 5db53f3 | 2009-11-20 20:13:39 +0100 | [diff] [blame] | 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) |
| 8 | |
| 9 | BTREE_TYPE_HEAD { |
| 10 | struct btree_head h; |
| 11 | }; |
| 12 | |
| 13 | static inline void BTREE_FN(init_mempool)(BTREE_TYPE_HEAD *head, |
| 14 | mempool_t *mempool) |
| 15 | { |
| 16 | btree_init_mempool(&head->h, mempool); |
| 17 | } |
| 18 | |
| 19 | static inline int BTREE_FN(init)(BTREE_TYPE_HEAD *head) |
| 20 | { |
| 21 | return btree_init(&head->h); |
| 22 | } |
| 23 | |
| 24 | static inline void BTREE_FN(destroy)(BTREE_TYPE_HEAD *head) |
| 25 | { |
| 26 | btree_destroy(&head->h); |
| 27 | } |
| 28 | |
| 29 | static inline int BTREE_FN(merge)(BTREE_TYPE_HEAD *target, |
| 30 | BTREE_TYPE_HEAD *victim, |
| 31 | gfp_t gfp) |
| 32 | { |
| 33 | return btree_merge(&target->h, &victim->h, BTREE_TYPE_GEO, gfp); |
| 34 | } |
| 35 | |
| 36 | #if (BITS_PER_LONG > BTREE_TYPE_BITS) |
| 37 | static inline void *BTREE_FN(lookup)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key) |
| 38 | { |
| 39 | unsigned long _key = key; |
| 40 | return btree_lookup(&head->h, BTREE_TYPE_GEO, &_key); |
| 41 | } |
| 42 | |
| 43 | static inline int BTREE_FN(insert)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key, |
| 44 | void *val, gfp_t gfp) |
| 45 | { |
| 46 | unsigned long _key = key; |
| 47 | return btree_insert(&head->h, BTREE_TYPE_GEO, &_key, val, gfp); |
| 48 | } |
| 49 | |
| 50 | static inline int BTREE_FN(update)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key, |
| 51 | void *val) |
| 52 | { |
| 53 | unsigned long _key = key; |
| 54 | return btree_update(&head->h, BTREE_TYPE_GEO, &_key, val); |
| 55 | } |
| 56 | |
| 57 | static inline void *BTREE_FN(remove)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key) |
| 58 | { |
| 59 | unsigned long _key = key; |
| 60 | return btree_remove(&head->h, BTREE_TYPE_GEO, &_key); |
| 61 | } |
| 62 | |
| 63 | static inline void *BTREE_FN(last)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key) |
| 64 | { |
| 65 | unsigned long _key; |
| 66 | void *val = btree_last(&head->h, BTREE_TYPE_GEO, &_key); |
| 67 | if (val) |
| 68 | *key = _key; |
| 69 | return val; |
| 70 | } |
| 71 | |
| 72 | static inline void *BTREE_FN(get_prev)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key) |
| 73 | { |
| 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; |
| 79 | } |
| 80 | #else |
| 81 | static inline void *BTREE_FN(lookup)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key) |
| 82 | { |
| 83 | return btree_lookup(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key); |
| 84 | } |
| 85 | |
| 86 | static inline int BTREE_FN(insert)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key, |
| 87 | void *val, gfp_t gfp) |
| 88 | { |
| 89 | return btree_insert(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key, |
| 90 | val, gfp); |
| 91 | } |
| 92 | |
| 93 | static inline int BTREE_FN(update)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key, |
| 94 | void *val) |
| 95 | { |
| 96 | return btree_update(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key, val); |
| 97 | } |
| 98 | |
| 99 | static inline void *BTREE_FN(remove)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE key) |
| 100 | { |
| 101 | return btree_remove(&head->h, BTREE_TYPE_GEO, (unsigned long *)&key); |
| 102 | } |
| 103 | |
| 104 | static inline void *BTREE_FN(last)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key) |
| 105 | { |
| 106 | return btree_last(&head->h, BTREE_TYPE_GEO, (unsigned long *)key); |
| 107 | } |
| 108 | |
| 109 | static inline void *BTREE_FN(get_prev)(BTREE_TYPE_HEAD *head, BTREE_KEYTYPE *key) |
| 110 | { |
| 111 | return btree_get_prev(&head->h, BTREE_TYPE_GEO, (unsigned long *)key); |
| 112 | } |
| 113 | #endif |
| 114 | |
| 115 | void VISITOR_FN(void *elem, unsigned long opaque, unsigned long *key, |
| 116 | size_t index, void *__func); |
| 117 | |
| 118 | typedef void (*VISITOR_FN_T)(void *elem, unsigned long opaque, |
| 119 | BTREE_KEYTYPE key, size_t index); |
| 120 | |
| 121 | static inline size_t BTREE_FN(visitor)(BTREE_TYPE_HEAD *head, |
| 122 | unsigned long opaque, |
| 123 | VISITOR_FN_T func2) |
| 124 | { |
| 125 | return btree_visitor(&head->h, BTREE_TYPE_GEO, opaque, |
| 126 | visitorl, func2); |
| 127 | } |
| 128 | |
| 129 | static inline size_t BTREE_FN(grim_visitor)(BTREE_TYPE_HEAD *head, |
| 130 | unsigned long opaque, |
| 131 | VISITOR_FN_T func2) |
| 132 | { |
| 133 | return btree_grim_visitor(&head->h, BTREE_TYPE_GEO, opaque, |
| 134 | visitorl, func2); |
| 135 | } |
| 136 | |
| 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 |