summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorVivek Ellur <vivek.ellur@samsung.com>2015-05-14 19:37:06 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-14 19:37:08 +0200
commit756ed9ccbabc202027ab2c15f25f48483e800b86 (patch)
tree1dfb8ddd048009f7040be41cd5c18856adef6248 /src/lib
parentc3a644acff12751891ef0ee78c1bba5106c7d9a4 (diff)
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>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/eina/eina_inarray.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/lib/eina/eina_inarray.c b/src/lib/eina/eina_inarray.c
index 2d52e6fd34..a216f0291b 100644
--- a/src/lib/eina/eina_inarray.c
+++ b/src/lib/eina/eina_inarray.c
@@ -150,12 +150,23 @@ _eina_inarray_get(const Eina_Inarray *array, unsigned int position)
150static int 150static int
151_eina_inarray_search(const Eina_Inarray *array, const void *data, Eina_Compare_Cb compare) 151_eina_inarray_search(const Eina_Inarray *array, const void *data, Eina_Compare_Cb compare)
152{ 152{
153 const unsigned char *start, *found; 153 unsigned int found, pos=-1;
154 start = array->members; 154 void *p;
155 found = bsearch(data, start, array->len, array->member_size, compare); 155
156 if (!found) 156 if (array->len == 0)
157 return -1;
158
159 for (pos = 0; pos < array->len; ++pos)
160 {
161 p = _eina_inarray_get(array, pos);
162 found = compare(data, p);
163 if (found == 0)
164 break;
165 }
166 if (pos < array->len)
167 return pos;
168 else
157 return -1; 169 return -1;
158 return (found - start) / array->member_size;
159} 170}
160 171
161static unsigned int 172static unsigned int