ReactOS  0.4.15-dev-3303-g1ade494
bsearch.c File Reference
#include <stdlib.h>
Include dependency graph for bsearch.c:

Go to the source code of this file.

Functions

void *__cdecl bsearch (const void *key, const void *base0, size_t nelem, size_t size, int(__cdecl *cmp)(const void *ck, const void *ce))
 

Function Documentation

◆ bsearch()

void* __cdecl bsearch ( const void key,
const void base0,
size_t  nelem,
size_t  size,
int(__cdecl *cmp)(const void *ck, const void *ce)   
)

Definition at line 9 of file bsearch.c.

11 {
12  char *base = (char *)base0;
13  size_t lim;
14  int cmpval;
15  void *p;
16 
17  for (lim = nelem; lim != 0; lim >>= 1)
18  {
19  p = base + (lim >> 1) * size;
20  cmpval = (*cmp)(key, p);
21  if (cmpval == 0)
22  return p;
23  if (cmpval > 0)
24  { /* key > p: move right */
25  base = (char *)p + size;
26  lim--;
27  } /* else move left */
28  }
29  return 0;
30 }
#define nelem(x)
Definition: shaptest.c:19
GLsizeiptr size
Definition: glext.h:5919
HKEY key
Definition: reg.c:42
GLfloat GLfloat p
Definition: glext.h:8902