mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-28 21:02:43 +01:00
Deduplicate the same functionality implemented in several places by moving the cmp_int() helper macro into linux/sort.h. The macro performs a three-way comparison of the arguments mostly useful in different sorting strategies and algorithms. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Fedor Pchelkin <[email protected]> Suggested-by: Darrick J. Wong <[email protected]> Acked-by: Kent Overstreet <[email protected]> Acked-by: Coly Li <[email protected]> Cc: Al Viro <[email protected]> Cc: Carlos Maiolino <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Coly Li <[email protected]> Cc: Jan Kara <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
38 lines
993 B
C
38 lines
993 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_SORT_H
|
|
#define _LINUX_SORT_H
|
|
|
|
#include <linux/types.h>
|
|
|
|
/**
|
|
* cmp_int - perform a three-way comparison of the arguments
|
|
* @l: the left argument
|
|
* @r: the right argument
|
|
*
|
|
* Return: 1 if the left argument is greater than the right one; 0 if the
|
|
* arguments are equal; -1 if the left argument is less than the right one.
|
|
*/
|
|
#define cmp_int(l, r) (((l) > (r)) - ((l) < (r)))
|
|
|
|
void sort_r(void *base, size_t num, size_t size,
|
|
cmp_r_func_t cmp_func,
|
|
swap_r_func_t swap_func,
|
|
const void *priv);
|
|
|
|
void sort(void *base, size_t num, size_t size,
|
|
cmp_func_t cmp_func,
|
|
swap_func_t swap_func);
|
|
|
|
/* Versions that periodically call cond_resched(): */
|
|
|
|
void sort_r_nonatomic(void *base, size_t num, size_t size,
|
|
cmp_r_func_t cmp_func,
|
|
swap_r_func_t swap_func,
|
|
const void *priv);
|
|
|
|
void sort_nonatomic(void *base, size_t num, size_t size,
|
|
cmp_func_t cmp_func,
|
|
swap_func_t swap_func);
|
|
|
|
#endif
|