114 e = e->next; |
114 e = e->next; |
115 } |
115 } |
116 return (UcxList*)e; |
116 return (UcxList*)e; |
117 } |
117 } |
118 |
118 |
|
119 ssize_t ucx_list_indexof(const UcxList *list, const UcxList *elem) { |
|
120 ssize_t index = 0; |
|
121 while (list) { |
|
122 if (list == elem) { |
|
123 return index; |
|
124 } |
|
125 list = list->next; |
|
126 index++; |
|
127 } |
|
128 return -1; |
|
129 } |
|
130 |
119 UcxList *ucx_list_get(const UcxList *l, int index) { |
131 UcxList *ucx_list_get(const UcxList *l, int index) { |
120 if (l == NULL) return NULL; |
132 if (l == NULL) return NULL; |
121 |
133 |
122 const UcxList *e = l; |
134 const UcxList *e = l; |
123 while (e->next != NULL && index > 0) { |
135 while (e->next != NULL && index > 0) { |
126 } |
138 } |
127 |
139 |
128 return (UcxList*)(index == 0 ? e : NULL); |
140 return (UcxList*)(index == 0 ? e : NULL); |
129 } |
141 } |
130 |
142 |
|
143 ssize_t ucx_list_find(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { |
|
144 ssize_t index = 0; |
|
145 UCX_FOREACH(e, l) { |
|
146 if (fnc(elem, e->data, cmpdata) == 0) { |
|
147 return index; |
|
148 } |
|
149 index++; |
|
150 } |
|
151 return -1; |
|
152 } |
|
153 |
131 int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { |
154 int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { |
132 UCX_FOREACH(e, l) { |
155 return ucx_list_find(l, elem, fnc, cmpdata) > -1; |
133 if (!fnc(elem, e->data, cmpdata)) { |
|
134 return 1; |
|
135 } |
|
136 } |
|
137 return 0; |
|
138 } |
156 } |
139 |
157 |
140 size_t ucx_list_size(const UcxList *l) { |
158 size_t ucx_list_size(const UcxList *l) { |
141 if (l == NULL) return 0; |
159 if (l == NULL) return 0; |
142 |
160 |