From 3e35e424d7b9b0036d93fc7314288c94063b513f Mon Sep 17 00:00:00 2001 From: Thomas Fitzsimmons Date: Thu, 4 Jul 2002 20:22:35 +0000 Subject: * Remove files (should have been done on 2002-06-20). --- newlib/libc/stdlib/bsearch.c | 100 ------------------------------------------- 1 file changed, 100 deletions(-) delete mode 100644 newlib/libc/stdlib/bsearch.c (limited to 'newlib/libc/stdlib/bsearch.c') diff --git a/newlib/libc/stdlib/bsearch.c b/newlib/libc/stdlib/bsearch.c deleted file mode 100644 index b9539aa3b..000000000 --- a/newlib/libc/stdlib/bsearch.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * bsearch.c - * Original Author: G. Haley - * Rewritten by: G. Noer - * - * Searches an array of nmemb members, the initial member of which is pointed - * to by base, for a member that matches the object pointed to by key. The - * contents of the array shall be in ascending order according to a comparison - * function pointed to by compar. The function shall return an integer less - * than, equal to or greater than zero if the first argument is considered to be - * respectively less than, equal to or greater than the second. Returns a - * pointer to the matching member of the array, or a null pointer if no match - * is found. - */ - -/* -FUNCTION -<>---binary search - -INDEX - bsearch - -ANSI_SYNOPSIS - #include - void *bsearch(const void *<[key]>, const void *<[base]>, - size_t <[nmemb]>, size_t <[size]>, - int (*<[compar]>)(const void *, const void *)); - -TRAD_SYNOPSIS - #include - char *bsearch(<[key]>, <[base]>, <[nmemb]>, <[size]>, <[compar]>) - char *<[key]>; - char *<[base]>; - size_t <[nmemb]>, <[size]>; - int (*<[compar]>)(); - -DESCRIPTION -<> searches an array beginning at <[base]> for any element -that matches <[key]>, using binary search. <[nmemb]> is the element -count of the array; <[size]> is the size of each element. - -The array must be sorted in ascending order with respect to the -comparison function <[compar]> (which you supply as the last argument of -<>). - -You must define the comparison function <<(*<[compar]>)>> to have two -arguments; its result must be negative if the first argument is -less than the second, zero if the two arguments match, and -positive if the first argument is greater than the second (where -``less than'' and ``greater than'' refer to whatever arbitrary -ordering is appropriate). - -RETURNS -Returns a pointer to an element of <[array]> that matches <[key]>. If -more than one matching element is available, the result may point to -any of them. - -PORTABILITY -<> is ANSI. - -No supporting OS subroutines are required. -*/ - -#include - -_PTR -_DEFUN (bsearch, (key, base, nmemb, size, compar), - _CONST _PTR key _AND - _CONST _PTR base _AND - size_t nmemb _AND - size_t size _AND - int _EXFUN ((*compar), (const _PTR, const _PTR))) -{ - _PTR current; - size_t lower = 0; - size_t upper = nmemb; - size_t index; - int result; - - if (nmemb == 0 || size == 0) - return NULL; - - while (lower < upper) - { - index = (lower + upper) / 2; - current = (_PTR) (((char *) base) + (index * size)); - - result = compar (key, current); - - if (result < 0) - upper = index; - else if (result > 0) - lower = index + 1; - else - return current; - } - - return NULL; -} - -- cgit v1.2.3