mirror of
https://github.com/torvalds/linux.git
synced 2026-07-30 19:21:28 +02:00
bcachefs: implement eytzinger0_find_ge directly
Implement eytzinger0_find_ge() directly instead of implementing it in terms of eytzinger0_find_le() and adjusting the result. This turns eytzinger0_find_ge() into a minimum search, so when there are duplicate elements, the result of eytzinger0_find_ge() will now always point at the first matching element. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
2182f29545
commit
11223d0e7b
|
|
@ -275,15 +275,17 @@ static inline int eytzinger0_find_gt(void *base, size_t nr, size_t size,
|
|||
return n - 1;
|
||||
}
|
||||
|
||||
/* return smallest node >= @search, or -1 if not found */
|
||||
static inline int eytzinger0_find_ge(void *base, size_t nr, size_t size,
|
||||
cmp_func_t cmp, const void *search)
|
||||
{
|
||||
ssize_t idx = eytzinger0_find_le(base, nr, size, cmp, search);
|
||||
void *base1 = base - size;
|
||||
unsigned n = 1;
|
||||
|
||||
if (idx < nr && !cmp(base + idx * size, search))
|
||||
return idx;
|
||||
|
||||
return eytzinger0_next(idx, nr);
|
||||
while (n <= nr)
|
||||
n = eytzinger1_child(n, cmp(base1 + n * size, search) < 0);
|
||||
n >>= __ffs(n + 1) + 1;
|
||||
return n - 1;
|
||||
}
|
||||
|
||||
#define eytzinger0_find(base, nr, size, _cmp, search) \
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user