-
Notifications
You must be signed in to change notification settings - Fork 3
/
cbtree-128.h
110 lines (90 loc) · 2.73 KB
/
cbtree-128.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* SPDX-License-Identifier: GPL-2.0 */
extern struct cbtree_geo cbtree_geo128;
struct cbtree_head128 { struct cbtree_head h; };
static inline void cbtree_init_mempool128(struct cbtree_head128 *head,
mempool_t *mempool)
{
cbtree_init_mempool(&head->h, mempool);
}
static inline int cbtree_init128(struct cbtree_head128 *head)
{
return cbtree_init(&head->h);
}
static inline void cbtree_destroy128(struct cbtree_head128 *head)
{
cbtree_destroy(&head->h);
}
static inline void *cbtree_lookup128(struct cbtree_head128 *head, u64 k1, u64 k2)
{
u64 key[2] = {k1, k2};
return cbtree_lookup(&head->h, &cbtree_geo128, (unsigned long *)&key);
}
static inline void *cbtree_get_prev128(struct cbtree_head128 *head,
u64 *k1, u64 *k2)
{
u64 key[2] = {*k1, *k2};
void *val;
val = cbtree_get_prev(&head->h, &cbtree_geo128,
(unsigned long *)&key);
*k1 = key[0];
*k2 = key[1];
return val;
}
static inline int cbtree_insert128(struct cbtree_head128 *head, u64 k1, u64 k2,
void *val, gfp_t gfp)
{
u64 key[2] = {k1, k2};
return cbtree_insert(&head->h, &cbtree_geo128,
(unsigned long *)&key, val, gfp);
}
static inline int cbtree_update128(struct cbtree_head128 *head, u64 k1, u64 k2,
void *val)
{
u64 key[2] = {k1, k2};
return cbtree_update(&head->h, &cbtree_geo128,
(unsigned long *)&key, val);
}
static inline void *cbtree_remove128(struct cbtree_head128 *head, u64 k1, u64 k2)
{
u64 key[2] = {k1, k2};
return cbtree_remove(&head->h, &cbtree_geo128, (unsigned long *)&key);
}
static inline void *cbtree_last128(struct cbtree_head128 *head, u64 *k1, u64 *k2)
{
u64 key[2];
void *val;
val = cbtree_last(&head->h, &cbtree_geo128, (unsigned long *)&key[0]);
if (val) {
*k1 = key[0];
*k2 = key[1];
}
return val;
}
static inline int cbtree_merge128(struct cbtree_head128 *target,
struct cbtree_head128 *victim,
gfp_t gfp)
{
return cbtree_merge(&target->h, &victim->h, &cbtree_geo128, gfp);
}
void cvisitor128(void *elem, unsigned long opaque, unsigned long *__key,
size_t index, void *__func);
typedef void (*visitor128_t)(void *elem, unsigned long opaque,
u64 key1, u64 key2, size_t index);
static inline size_t cbtree_cvisitor128(struct cbtree_head128 *head,
unsigned long opaque,
visitor128_t func2)
{
return cbtree_visitor(&head->h, &cbtree_geo128, opaque,
cvisitor128, func2);
}
static inline size_t cbtree_grim_cvisitor128(struct cbtree_head128 *head,
unsigned long opaque,
visitor128_t func2)
{
return cbtree_grim_visitor(&head->h, &cbtree_geo128, opaque,
cvisitor128, func2);
}
#define cbtree_for_each_safe128(head, k1, k2, val) \
for (val = cbtree_last128(head, &k1, &k2); \
val; \
val = cbtree_get_prev128(head, &k1, &k2))