PandA-2024.02
bsearch.c
Go to the documentation of this file.
1 typedef unsigned int size_t;
2 #define NULL 0
3 void *bsearch(const void *key, const void *base, size_t /* nmemb */ high,
4  size_t size, int (*compar)(const void *, const void *))
5 {
6  register char *p;
7  size_t low;
8  size_t mid;
9  int r;
10 
11  if (size > 0) { /* TODO: change this to an assert?? */
12  low = 0;
13  while (low < high) {
14  mid = low + ((high - low) >> 1); /* Avoid possible overflow here. */
15  p = ((char *)base) + mid * size; /* Could overflow here... */
16  r = (*compar)(key, p); /* but that's an application problem! */
17  if (r > 0) {
18  low = mid + 1;
19  } else if (r < 0) {
20  high = mid;
21  } else {
22  return p;
23  }
24  }
25  }
26  return NULL;
27 }
char base
This version is stamped on May 10, 2016.
Definition: nussinov.c:24
void * bsearch(const void *__key, const void *__base, size_t __nmemb, size_t __size, int(*__compar)(const void *, const void *))
Definition: bsearch.c:23
#define NULL
Definition: bsearch.c:2
int key[32]
Definition: aes.h:67
int compar(const void *v_lhs, const void *v_rhs)
Definition: generate.c:16
unsigned int size_t
Definition: bsearch.c:19

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