diff options
| author | Andreas Gruenbacher <agruenba@redhat.com> | 2025-01-27 17:05:21 +0100 |
|---|---|---|
| committer | Kent Overstreet <kent.overstreet@linux.dev> | 2025-03-14 21:02:13 -0400 |
| commit | d7cd33f7efbb91893bb20aa2baae4f8c37dd035a (patch) | |
| tree | 0281a97c92c06bcaf67d62dfe2776fc2afdaf71f /fs/bcachefs/util.c | |
| parent | bcachefs: simplify eytzinger0_find_le (diff) | |
| download | linux-d7cd33f7efbb91893bb20aa2baae4f8c37dd035a.tar.gz linux-d7cd33f7efbb91893bb20aa2baae4f8c37dd035a.zip | |
bcachefs: add eytzinger0_find_gt self test
Add an eytzinger0_find_gt() self test similar to eytzinger0_find_le().
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/util.c')
| -rw-r--r-- | fs/bcachefs/util.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/fs/bcachefs/util.c b/fs/bcachefs/util.c index d2f7ffcc4fd6..9c6e5d7122b4 100644 --- a/fs/bcachefs/util.c +++ b/fs/bcachefs/util.c @@ -825,9 +825,47 @@ static void eytzinger0_find_test_le(u16 *test_array, unsigned nr, u16 search) } } +static void eytzinger0_find_test_gt(u16 *test_array, unsigned nr, u16 search) +{ + int r, s; + bool bad; + + r = eytzinger0_find_gt(test_array, nr, + sizeof(test_array[0]), + cmp_u16, &search); + if (r >= 0) { + if (test_array[r] <= search) { + bad = true; + } else { + s = eytzinger0_prev(r, nr); + bad = s >= 0 && test_array[s] > search; + } + } else { + s = eytzinger0_first(nr); + bad = s >= 0 && test_array[s] > search; + } + + if (bad) { + s = -1; + eytzinger0_for_each(j, nr) { + if (test_array[j] > search) { + s = j; + break; + } + } + + eytzinger0_for_each(j, nr) + pr_info("[%3u] = %12u\n", j, test_array[j]); + pr_info("find_gt(%12u) = %3i should be %3i\n", + search, r, s); + BUG(); + } +} + static void eytzinger0_find_test_val(u16 *test_array, unsigned nr, u16 search) { eytzinger0_find_test_le(test_array, nr, search); + eytzinger0_find_test_gt(test_array, nr, search); } void eytzinger0_find_test(void) |
