PandA-2024.02
examples
function_pointers
bsearch
glibc
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
}
NULL
#define NULL
Definition:
bsearch-specialized.c:20
bsearch
void * bsearch(const void *__key, const void *__base, size_t __nmemb, size_t __size, int(*__compar)(const void *, const void *))
Definition:
bsearch-specialized.c:25
less
int less(const void *a, const void *b)
Definition:
less.c:4
size_t
unsigned int size_t
Definition:
bsearch-specialized.c:19
Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by
1.8.13