X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fbsearch.c;fp=functions%2Fstdlib%2Fbsearch.c;h=c03cd45716e435b884a01f5b8e4ac20ea12decc4;hb=0a5395faab237ba9008352b0f4bee9659bbd3d5f;hp=056028623c209837ffbdd981e88567496b7fce04;hpb=34893ecc2200dc7017c36a54cb6c5f4c2378b5ec;p=pdclib diff --git a/functions/stdlib/bsearch.c b/functions/stdlib/bsearch.c index 0560286..c03cd45 100644 --- a/functions/stdlib/bsearch.c +++ b/functions/stdlib/bsearch.c @@ -7,3 +7,32 @@ // 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); +} +*/