blob: bf86aa66f2b275798ae850e321a1a459d1a6bfab [file] [log] [blame]
Thomas Gleixnera10e7632019-05-31 01:09:32 -07001// SPDX-License-Identifier: GPL-2.0-only
Tim Abbott1a94dc32011-04-14 20:00:19 +02002/*
3 * A generic implementation of binary search for the Linux kernel
4 *
5 * Copyright (C) 2008-2009 Ksplice, Inc.
6 * Author: Tim Abbott <tabbott@ksplice.com>
Tim Abbott1a94dc32011-04-14 20:00:19 +02007 */
8
Paul Gortmaker8bc3bcc2011-11-16 21:29:17 -05009#include <linux/export.h>
Tim Abbott1a94dc32011-04-14 20:00:19 +020010#include <linux/bsearch.h>
Andrea Righi02106f82019-02-13 01:15:34 +090011#include <linux/kprobes.h>
Tim Abbott1a94dc32011-04-14 20:00:19 +020012
13/*
14 * bsearch - binary search an array of elements
15 * @key: pointer to item being searched for
16 * @base: pointer to first element to search
17 * @num: number of elements
18 * @size: size of each element
19 * @cmp: pointer to comparison function
20 *
21 * This function does a binary search on the given array. The
22 * contents of the array should already be in ascending sorted order
23 * under the provided comparison function.
24 *
25 * Note that the key need not have the same type as the elements in
26 * the array, e.g. key could be a string and the comparison function
27 * could compare the string with the struct's name field. However, if
28 * the key and elements in the array are of the same type, you can use
29 * the same comparison function for both sort() and bsearch().
30 */
Peter Zijlstradf65bba2020-02-19 18:25:09 +010031void *bsearch(const void *key, const void *base, size_t num, size_t size, cmp_func_t cmp)
Tim Abbott1a94dc32011-04-14 20:00:19 +020032{
Peter Zijlstradf65bba2020-02-19 18:25:09 +010033 return __inline_bsearch(key, base, num, size, cmp);
Tim Abbott1a94dc32011-04-14 20:00:19 +020034}
35EXPORT_SYMBOL(bsearch);
Andrea Righi02106f82019-02-13 01:15:34 +090036NOKPROBE_SYMBOL(bsearch);