X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fbsearch.c;h=c03cd45716e435b884a01f5b8e4ac20ea12decc4;hb=e5456e3c2697c4e17fc9aa3439f2e305517b4d96;hp=056028623c209837ffbdd981e88567496b7fce04;hpb=dcc8a8e99f69e090a03b7b868443addbc0817820;p=pdclib.old 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); +} +*/