Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / include / linux / btree-128.h
blob22c09f5c3c39c36d567261e7c4f8fa84924fd43f
1 /* SPDX-License-Identifier: GPL-2.0 */
2 extern struct btree_geo btree_geo128;
4 struct btree_head128 { struct btree_head h; };
6 static inline void btree_init_mempool128(struct btree_head128 *head,
7 mempool_t *mempool)
9 btree_init_mempool(&head->h, mempool);
12 static inline int btree_init128(struct btree_head128 *head)
14 return btree_init(&head->h);
17 static inline void btree_destroy128(struct btree_head128 *head)
19 btree_destroy(&head->h);
22 static inline void *btree_lookup128(struct btree_head128 *head, u64 k1, u64 k2)
24 u64 key[2] = {k1, k2};
25 return btree_lookup(&head->h, &btree_geo128, (unsigned long *)&key);
28 static inline void *btree_get_prev128(struct btree_head128 *head,
29 u64 *k1, u64 *k2)
31 u64 key[2] = {*k1, *k2};
32 void *val;
34 val = btree_get_prev(&head->h, &btree_geo128,
35 (unsigned long *)&key);
36 *k1 = key[0];
37 *k2 = key[1];
38 return val;
41 static inline int btree_insert128(struct btree_head128 *head, u64 k1, u64 k2,
42 void *val, gfp_t gfp)
44 u64 key[2] = {k1, k2};
45 return btree_insert(&head->h, &btree_geo128,
46 (unsigned long *)&key, val, gfp);
49 static inline int btree_update128(struct btree_head128 *head, u64 k1, u64 k2,
50 void *val)
52 u64 key[2] = {k1, k2};
53 return btree_update(&head->h, &btree_geo128,
54 (unsigned long *)&key, val);
57 static inline void *btree_remove128(struct btree_head128 *head, u64 k1, u64 k2)
59 u64 key[2] = {k1, k2};
60 return btree_remove(&head->h, &btree_geo128, (unsigned long *)&key);
63 static inline void *btree_last128(struct btree_head128 *head, u64 *k1, u64 *k2)
65 u64 key[2];
66 void *val;
68 val = btree_last(&head->h, &btree_geo128, (unsigned long *)&key[0]);
69 if (val) {
70 *k1 = key[0];
71 *k2 = key[1];
74 return val;
77 static inline int btree_merge128(struct btree_head128 *target,
78 struct btree_head128 *victim,
79 gfp_t gfp)
81 return btree_merge(&target->h, &victim->h, &btree_geo128, gfp);
84 void visitor128(void *elem, unsigned long opaque, unsigned long *__key,
85 size_t index, void *__func);
87 typedef void (*visitor128_t)(void *elem, unsigned long opaque,
88 u64 key1, u64 key2, size_t index);
90 static inline size_t btree_visitor128(struct btree_head128 *head,
91 unsigned long opaque,
92 visitor128_t func2)
94 return btree_visitor(&head->h, &btree_geo128, opaque,
95 visitor128, func2);
98 static inline size_t btree_grim_visitor128(struct btree_head128 *head,
99 unsigned long opaque,
100 visitor128_t func2)
102 return btree_grim_visitor(&head->h, &btree_geo128, opaque,
103 visitor128, func2);
106 #define btree_for_each_safe128(head, k1, k2, val) \
107 for (val = btree_last128(head, &k1, &k2); \
108 val; \
109 val = btree_get_prev128(head, &k1, &k2))