Rewrote some stuff to work w/ pointer math

This commit is contained in:
Gitea 2020-12-21 20:54:41 -06:00
parent f85337e404
commit 8fd6c4b295

View file

@ -13,22 +13,22 @@
void * bsearch(const void * key, const void * base, size_t nel, size_t width,
int (*compar)(const void *, const void*)) {
void * left;
void * right;
void * mid;
long int left;
long int right;
long int mid;
if(nel == 0 || base == NULL) {
return NULL;
}
left = base;
right = base + (nel * width);
left = (long int) base;
right = (long int) (base + (nel * width));
while(left <= right) {
mid = (left + right) / 2;
int t = compar(key, mid);
int t = compar(key, (void *) mid);
if(t == 0) {
return mid;
return (void *) mid;
}
else if(t < 0) {
right = mid - width;