PandA-2024.02
bsearch.c
Go to the documentation of this file.
1 /* Perform binary search - inline version.
2  Copyright (C) 1991-2014 Free Software Foundation, Inc.
3  This file is part of the GNU C Library.
4 
5  The GNU C Library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  The GNU C Library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with the GNU C Library; if not, see
17  <http://www.gnu.org/licenses/>. */
18 
19 typedef unsigned int size_t;
20 #define NULL 0
21 
22 void *
23 bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
24  int (*__compar)(const void *, const void *))
25 {
26  size_t __l, __u, __idx;
27  const void *__p;
28  int __comparison;
29 
30  __l = 0;
31  __u = __nmemb;
32  while (__l < __u)
33  {
34  __idx = (__l + __u) / 2;
35  __p = (void *) (((const char *) __base) + (__idx * __size));
36  __comparison = (*__compar) (__key, __p);
37  if (__comparison < 0)
38  __u = __idx;
39  else if (__comparison > 0)
40  __l = __idx + 1;
41  else
42  return (void *) __p;
43  }
44 
45  return NULL;
46 }
void * bsearch(const void *__key, const void *__base, size_t __nmemb, size_t __size, int(*__compar)(const void *, const void *))
Definition: bsearch.c:23
unsigned int size_t
Definition: bsearch.c:19
#define NULL
Definition: bsearch.c:20

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13