C: simplify hamming/binary search
This commit is contained in:
@@ -4,8 +4,7 @@ const int *binary_search(int v, const int *a, size_t size)
|
||||
{
|
||||
size_t lo, hi, i;
|
||||
|
||||
/* quickly exclude invalid/trivial results :
|
||||
* NULL or empty array, value out of bounds
|
||||
/* early exclude invalid/trivial result: NULL/empty array, value off bounds
|
||||
*/
|
||||
if (!size || !a || v < *a || v > *(a+size-1))
|
||||
return NULL;
|
||||
@@ -22,7 +21,6 @@ const int *binary_search(int v, const int *a, size_t size)
|
||||
* https://github.com/braoult/exercism/blob/master/c/templates/GNUmakefile
|
||||
*/
|
||||
#ifdef UNIT_TEST
|
||||
#include <stdio.h>
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int arg=1, *res;
|
||||
|
@@ -12,6 +12,7 @@ const int *binary_search(int value, const int *arr, size_t length);
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef TESTALL
|
||||
#undef TEST_IGNORE
|
||||
#define TEST_IGNORE() {}
|
||||
|
Reference in New Issue
Block a user