barray: Work with more compare functions

Currently, this code requires a compare functions to return either -1, 0 or 1.
Values outside of this range will result in endless loops. Fix this by using if
instead of switch() for the result of the compare function.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-09-01 15:37:21 +02:00
parent e1b15b2bb8
commit 0783ee8ffb

View file

@ -117,17 +117,13 @@
while(l < r) \
{ \
int i = (r + l) / 2; \
switch(cmp(&e, &arr->tab[i])) \
{ \
case -1: \
int res = cmp(&e, &arr->tab[i]); \
if(res == 0) \
return; /* Already added, ignore */ \
if(res < 0) \
r = i; \
break; \
case 0: \
return; \
case 1: \
else \
l = i + 1; \
break; \
} \
} \
pfx##_array_splice(arr, r, 0, &e, 1); \
} \