]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1a94dc35 TA |
2 | #ifndef _LINUX_BSEARCH_H |
3 | #define _LINUX_BSEARCH_H | |
4 | ||
5 | #include <linux/types.h> | |
6 | ||
df65bba1 PZ |
7 | static __always_inline |
8 | void *__inline_bsearch(const void *key, const void *base, size_t num, size_t size, cmp_func_t cmp) | |
9 | { | |
10 | const char *pivot; | |
11 | int result; | |
12 | ||
13 | while (num > 0) { | |
14 | pivot = base + (num >> 1) * size; | |
15 | result = cmp(key, pivot); | |
16 | ||
17 | if (result == 0) | |
18 | return (void *)pivot; | |
19 | ||
20 | if (result > 0) { | |
21 | base = pivot + size; | |
22 | num--; | |
23 | } | |
24 | num >>= 1; | |
25 | } | |
26 | ||
27 | return NULL; | |
28 | } | |
29 | ||
30 | extern void *bsearch(const void *key, const void *base, size_t num, size_t size, cmp_func_t cmp); | |
1a94dc35 TA |
31 | |
32 | #endif /* _LINUX_BSEARCH_H */ |