diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2017-10-05 14:41:44 -0800 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2017-10-08 10:25:33 -0800 |
commit | 85ee972555948337bb1a58f0702a4da95db6758f (patch) | |
tree | 34f13bce6d9ad221593a45d3ee3b489b777cba04 /libbcachefs/eytzinger.h | |
parent | e7c2bb91bce30a987c8c4e2875f2c63e887d3aa5 (diff) |
Update bcachefs sources to e82e656279 bcachefs: Cleanups for building in userspace
Diffstat (limited to 'libbcachefs/eytzinger.h')
-rw-r--r-- | libbcachefs/eytzinger.h | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/libbcachefs/eytzinger.h b/libbcachefs/eytzinger.h index dc23e44d..04dcfc50 100644 --- a/libbcachefs/eytzinger.h +++ b/libbcachefs/eytzinger.h @@ -259,29 +259,31 @@ static inline unsigned inorder_to_eytzinger0(unsigned i, unsigned size) return __inorder_to_eytzinger0(i, size, eytzinger0_extra(size)); } -#define eytzinger0_find(base, _nr, _size, _cmp, _search) \ -({ \ - void *_base = base; \ - size_t _i = 0; \ - int _res; \ - \ - while (_i < (_nr) && \ - (_res = _cmp(_search, _base + _i * (_size), _size))) \ - _i = eytzinger0_child(_i, _res > 0); \ - \ - if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG)) { \ - bool found1 = _i < _nr, found2 = false; \ - unsigned _j; \ - \ - for (_j = 0; _j < _nr; _j++) \ - if (!_cmp(_base + _j * (_size), _search, _size))\ - found2 = true; \ - \ - BUG_ON(found1 != found2); \ - } \ - \ - _i; \ -}) +typedef int (*eytzinger_cmp_fn)(const void *l, const void *r, size_t size); + +static inline size_t eytzinger0_find(void *base, size_t nr, size_t size, + eytzinger_cmp_fn cmp, void *search) +{ + size_t i = 0; + int res; + + while (i < nr && + (res = cmp(search, base + i * size, size))) + i = eytzinger0_child(i, res > 0); + + if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG)) { + bool found1 = i < nr, found2 = false; + size_t j; + + for (j = 0; j < nr; j++) + if (!cmp(base + j * size, search, size)) + found2 = true; + + BUG_ON(found1 != found2); + } + + return i; +} void eytzinger0_sort(void *, size_t, size_t, int (*cmp_func)(const void *, const void *, size_t), |