PandA-2024.02
bsearch-specialized.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 int less (const void * a, const void * b);
23 
24 void *
25 bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
26  int (*__compar)(const void *, const void *))
27 {
28  size_t __l, __u, __idx;
29  const void *__p;
30  int __comparison;
31 
32  __l = 0;
33  __u = __nmemb;
34  while (__l < __u)
35  {
36  __idx = (__l + __u) / 2;
37  __p = (void *) (((const char *) __base) + (__idx * __size));
38  __comparison = less (__key, __p);
39  if (__comparison < 0)
40  __u = __idx;
41  else if (__comparison > 0)
42  __l = __idx + 1;
43  else
44  return (void *) __p;
45  }
46 
47  return NULL;
48 }
#define NULL
void * bsearch(const void *__key, const void *__base, size_t __nmemb, size_t __size, int(*__compar)(const void *, const void *))
int less(const void *a, const void *b)
Definition: less.c:4
unsigned int size_t

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