152 |
152 |
153 UcxList *ucx_list_get(const UcxList *l, int index) { |
153 UcxList *ucx_list_get(const UcxList *l, int index) { |
154 if (l == NULL) return NULL; |
154 if (l == NULL) return NULL; |
155 |
155 |
156 const UcxList *e = l; |
156 const UcxList *e = l; |
157 while (e->next != NULL && index > 0) { |
157 while (e->next && index > 0) { |
158 e = e->next; |
158 e = e->next; |
159 index--; |
159 index--; |
160 } |
160 } |
161 |
161 |
162 return (UcxList*)(index == 0 ? e : NULL); |
162 return (UcxList*)(index == 0 ? e : NULL); |
163 } |
163 } |
164 |
164 |
165 ssize_t ucx_list_find(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { |
165 ssize_t ucx_list_find(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { |
166 ssize_t index = 0; |
166 ssize_t index = 0; |
167 UCX_FOREACH(e, l) { |
167 UCX_FOREACH(e, l) { |
168 if (fnc(elem, e->data, cmpdata) == 0) { |
168 if (fnc) { |
169 return index; |
169 if (fnc(elem, e->data, cmpdata) == 0) { |
|
170 return index; |
|
171 } |
|
172 } else { |
|
173 if (elem == e->data) { |
|
174 return index; |
|
175 } |
170 } |
176 } |
171 index++; |
177 index++; |
172 } |
178 } |
173 return -1; |
179 return -1; |
174 } |
180 } |