Rewrote some stuff to work w/ pointer math
This commit is contained in:
parent
f85337e404
commit
8fd6c4b295
1 changed files with 7 additions and 7 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue