summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/util.c
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruenba@redhat.com>2025-01-28 18:24:15 +0100
committerKent Overstreet <kent.overstreet@linux.dev>2025-03-14 21:02:14 -0400
commitf27614652cd33184fb8a8464c1b0b893d350b33d (patch)
tree67c642c24fdc214456c2ba8dfb9d5e5ab67e9558 /fs/bcachefs/util.c
parentbcachefs: convert eytzinger sort to be 1-based (2) (diff)
downloadlinux-f27614652cd33184fb8a8464c1b0b893d350b33d.tar.gz
linux-f27614652cd33184fb8a8464c1b0b893d350b33d.zip
bcachefs: eytzinger1_{next,prev} cleanup
The eytzinger code was previously relying on the following wrap-around properties and their "eytzinger0" equivalents: eytzinger1_prev(0, size) == eytzinger1_last(size) eytzinger1_next(0, size) == eytzinger1_first(size) However, these properties are no longer relied upon and no longer necessary, so remove the corresponding asserts and forbid the use of eytzinger1_prev(0, size) and eytzinger1_next(0, size). This allows to further simplify the code in eytzinger1_next() and eytzinger1_prev(): where the left shifting happens, eytzinger1_next() is trying to move i to the lowest child on the left, which is equivalent to doubling i until the next doubling would cause it to be greater than size. This is implemented by shifting i to the left so that the most significant bits align and then shifting i to the right by one if the result is greater than size. Likewise, eytzinger1_prev() is trying to move to the lowest child on the right; the same applies here. The 1-offset in (size - 1) in eytzinger1_next() isn't needed at all, but the equivalent offset in eytzinger1_prev() is surprisingly needed to preserve the 'eytzinger1_prev(0, size) == eytzinger1_last(size)' property. However, since we no longer support that property, we can get rid of these offsets as well. This saves one addition in each function and makes the code less confusing. 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.c12
1 files changed, 0 insertions, 12 deletions
diff --git a/fs/bcachefs/util.c b/fs/bcachefs/util.c
index 525734528f35..a7edbcca1a84 100644
--- a/fs/bcachefs/util.c
+++ b/fs/bcachefs/util.c
@@ -719,12 +719,6 @@ void eytzinger1_test(void)
if (!(size % 4096))
pr_info("tree size %u\n", size);
- BUG_ON(eytzinger1_prev(0, size) != eytzinger1_last(size));
- BUG_ON(eytzinger1_next(0, size) != eytzinger1_first(size));
-
- BUG_ON(eytzinger1_prev(eytzinger1_first(size), size) != 0);
- BUG_ON(eytzinger1_next(eytzinger1_last(size), size) != 0);
-
inorder = 1;
eytzinger1_for_each(eytz, size) {
BUG_ON(__inorder_to_eytzinger1(inorder, size, extra) != eytz);
@@ -753,12 +747,6 @@ void eytzinger0_test(void)
if (!(size % 4096))
pr_info("tree size %u\n", size);
- BUG_ON(eytzinger0_prev(-1, size) != eytzinger0_last(size));
- BUG_ON(eytzinger0_next(-1, size) != eytzinger0_first(size));
-
- BUG_ON(eytzinger0_prev(eytzinger0_first(size), size) != -1);
- BUG_ON(eytzinger0_next(eytzinger0_last(size), size) != -1);
-
inorder = 0;
eytzinger0_for_each(eytz, size) {
BUG_ON(__inorder_to_eytzinger0(inorder, size, extra) != eytz);