summaryrefslogtreecommitdiff
path: root/fs/bcachefs/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/bcachefs/util.h')
-rw-r--r--fs/bcachefs/util.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
index 6e97e83184e1..9aadb7371ffb 100644
--- a/fs/bcachefs/util.h
+++ b/fs/bcachefs/util.h
@@ -817,4 +817,19 @@ do { \
#define array_remove_item(_array, _nr, _pos) \
array_remove_items(_array, _nr, _pos, 1)
+#define bubble_sort(_base, _nr, _cmp) \
+do { \
+ unsigned _i, _end; \
+ bool _swapped = true; \
+ \
+ for (_end = (_nr) - 1; _end && _swapped; --_end) { \
+ _swapped = false; \
+ for (_i = 0; _i < _end; _i++) \
+ if (_cmp((_base)[_i], (_base)[_i + 1]) > 0) { \
+ swap((_base)[_i], (_base)[_i + 1]); \
+ _swapped = true; \
+ } \
+ } \
+} while (0)
+
#endif /* _BCACHEFS_UTIL_H */