From: Andreas Gruenbacher Date: Tue, 28 Jan 2025 09:56:37 +0000 (+0100) Subject: bcachefs: convert eytzinger0_find to be 1-based X-Git-Tag: v6.15-rc1~146^2~111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3849bcab4d3f0cf1aee56bdfc7bcae7b40b11657;p=thirdparty%2Fkernel%2Flinux.git bcachefs: convert eytzinger0_find to be 1-based Several of the algorithms on eytzinger trees are implemented in terms of the eytzinger0 primitives. However, those algorithms can just as easily be expressed in terms of the eytzinger1 primitives, and that leads to better and easier to understand code. Start by converting eytzinger0_find(). Signed-off-by: Andreas Gruenbacher Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/eytzinger.h b/fs/bcachefs/eytzinger.h index e3713b7b4c276..90cd5648b1777 100644 --- a/fs/bcachefs/eytzinger.h +++ b/fs/bcachefs/eytzinger.h @@ -290,17 +290,17 @@ static inline int eytzinger0_find_ge(void *base, size_t nr, size_t size, #define eytzinger0_find(base, nr, size, _cmp, search) \ ({ \ - void *_base = (base); \ + size_t _size = (size); \ + void *_base1 = (void *)(base) - _size; \ const void *_search = (search); \ size_t _nr = (nr); \ - size_t _size = (size); \ - size_t _i = 0; \ + size_t _i = 1; \ int _res; \ \ - while (_i < _nr && \ - (_res = _cmp(_search, _base + _i * _size))) \ - _i = eytzinger0_child(_i, _res > 0); \ - _i; \ + while (_i <= _nr && \ + (_res = _cmp(_search, _base1 + _i * _size))) \ + _i = eytzinger1_child(_i, _res > 0); \ + _i - 1; \ }) void eytzinger0_sort_r(void *, size_t, size_t,