Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenbsearch.c
Go to the documentation of this file.
00001 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 00002 #include <stdlib.h> 00003 00004 /* 00005 * @implemented 00006 */ 00007 void * 00008 bsearch(const void *key, const void *base0, size_t nelem, 00009 size_t size, int (__cdecl *cmp)(const void *ck, const void *ce)) 00010 { 00011 char *base = (char *)base0; 00012 size_t lim; 00013 int cmpval; 00014 void *p; 00015 00016 for (lim = nelem; lim != 0; lim >>= 1) 00017 { 00018 p = base + (lim >> 1) * size; 00019 cmpval = (*cmp)(key, p); 00020 if (cmpval == 0) 00021 return p; 00022 if (cmpval > 0) 00023 { /* key > p: move right */ 00024 base = (char *)p + size; 00025 lim--; 00026 } /* else move left */ 00027 } 00028 return 0; 00029 } Generated on Sun May 27 2012 04:36:36 for ReactOS by
1.7.6.1
|