Search the list for a node matching a given key. * The match is performed using the 'match' method * set with listSetMatchMethod(). If no 'match' method * is set, the 'value' pointer of every node is directly * compared with the 'key' pointer. * * On success the first matching node pointer is returned * (search starts from head). If no matching node exists * NULL is returned. */
| 289 | * (search starts from head). If no matching node exists |
| 290 | * NULL is returned. */ |
| 291 | listNode *listSearchKey(list *list, void *key) |
| 292 | { |
| 293 | listIter iter; |
| 294 | listNode *node; |
| 295 | |
| 296 | listRewind(list, &iter); |
| 297 | while((node = listNext(&iter)) != NULL) { |
| 298 | if (list->match) { |
| 299 | if (list->match(node->value, key)) { |
| 300 | return node; |
| 301 | } |
| 302 | } else { |
| 303 | if (key == node->value) { |
| 304 | return node; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | return NULL; |
| 309 | } |
| 310 | |
| 311 | /* Return the element at the specified zero-based index |
| 312 | * where 0 is the head, 1 is the element next to head |
no test coverage detected