diff options
author | Tim Abbott <tabbott@ksplice.com> | 2011-04-14 20:00:19 +0200 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-05-19 16:55:27 +0930 |
commit | 1a94dc35bc5c166d89913dc01a49d27a3c21a455 (patch) | |
tree | 575196f1d0b9528b7d63b9bff692dd81e1aeac0f /include/linux/bsearch.h | |
parent | f02e8a6596b7dc9b2171f7ff5654039ef0950cdc (diff) |
lib: Add generic binary search function to the kernel.
There a large number hand-coded binary searches in the kernel (run
"git grep search | grep binary" to find many of them). Since in my
experience, hand-coding binary searches can be error-prone, it seems
worth cleaning this up by providing a generic binary search function.
This generic binary search implementation comes from Ksplice. It has
the same basic API as the C library bsearch() function. Ksplice uses
it in half a dozen places with 4 different comparison functions, and I
think our code is substantially cleaner because of this.
Signed-off-by: Tim Abbott <tabbott@ksplice.com>
Extra-bikeshedding-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Extra-bikeshedding-by: André Goddard Rosa <andre.goddard@gmail.com>
Extra-bikeshedding-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Alessio Igor Bogani <abogani@kernel.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'include/linux/bsearch.h')
-rw-r--r-- | include/linux/bsearch.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/include/linux/bsearch.h b/include/linux/bsearch.h new file mode 100644 index 000000000000..90b1aa867224 --- /dev/null +++ b/include/linux/bsearch.h @@ -0,0 +1,9 @@ +#ifndef _LINUX_BSEARCH_H +#define _LINUX_BSEARCH_H + +#include <linux/types.h> + +void *bsearch(const void *key, const void *base, size_t num, size_t size, + int (*cmp)(const void *key, const void *elt)); + +#endif /* _LINUX_BSEARCH_H */ |