forked from enlightenment/efl
eina: fix eina_inarray_search to do linear search
Summary: Currently eina_inarray_search was using binary search to search elements which would not work on unsorted array so modified it to work as linear search. There is already a function eina_inarray_search_sorted to work on sorted array. Signed-off-by: Vivek Ellur <vivek.ellur@samsung.com> Reviewers: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2501 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
parent
c3a644acff
commit
756ed9ccba
|
@ -150,12 +150,23 @@ _eina_inarray_get(const Eina_Inarray *array, unsigned int position)
|
|||
static int
|
||||
_eina_inarray_search(const Eina_Inarray *array, const void *data, Eina_Compare_Cb compare)
|
||||
{
|
||||
const unsigned char *start, *found;
|
||||
start = array->members;
|
||||
found = bsearch(data, start, array->len, array->member_size, compare);
|
||||
if (!found)
|
||||
unsigned int found, pos=-1;
|
||||
void *p;
|
||||
|
||||
if (array->len == 0)
|
||||
return -1;
|
||||
|
||||
for (pos = 0; pos < array->len; ++pos)
|
||||
{
|
||||
p = _eina_inarray_get(array, pos);
|
||||
found = compare(data, p);
|
||||
if (found == 0)
|
||||
break;
|
||||
}
|
||||
if (pos < array->len)
|
||||
return pos;
|
||||
else
|
||||
return -1;
|
||||
return (found - start) / array->member_size;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
|
|
Loading…
Reference in New Issue