C: simplify hamming/binary search

This commit is contained in:
2021-08-20 16:41:13 +02:00
parent 01fcdc8566
commit 6c5e61efe9
4 changed files with 13 additions and 21 deletions

View File

@@ -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;

View File

@@ -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() {}