X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdlib%2Fbsearch.c;h=fa58d0d0ffec7f6657de39d65527cd721e711288;hp=056028623c209837ffbdd981e88567496b7fce04;hb=1d9d92ba957a0b8307c9a65c35867fde68e6533b;hpb=34893ecc2200dc7017c36a54cb6c5f4c2378b5ec diff --git a/functions/stdlib/bsearch.c b/functions/stdlib/bsearch.c index 0560286..fa58d0d 100644 --- a/functions/stdlib/bsearch.c +++ b/functions/stdlib/bsearch.c @@ -1,9 +1,37 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- +/* ---------------------------------------------------------------------------- + * $Id$ + * ---------------------------------------------------------------------------- + * Public Domain C Library - http://pdclib.sourceforge.net + * This code is Public Domain. Use, modify, and redistribute at will. + * --------------------------------------------------------------------------*/ -// TODO: C/C++ linkage void * bsearch( const void * key, const void * base, size_t nelem, size_t size, int (*cmp) ( const void * ck, const void * ce) ) { /* TODO */ }; + +/* PDPC code - unreviewed +{ + size_t try; + int res; + const void *ptr; + + while (nmemb > 0) + { + try = nmemb / 2; + ptr = (void *)((char *)base + try * size); + res = compar(ptr, key); + if (res == 0) + { + return ((void *)ptr); + } + else if (res < 0) + { + nmemb = nmemb - try - 1; + base = (const void *)((const char *)ptr + size); + } + else + { + nmemb = try; + } + } + return (NULL); +} +*/