bool list_find(list_t *list, const void *element) { list_node_t *node = list->head; list_atcache_thrash(list); for(size_t index = 0; node && node->element != element; node = node->next, index++) list_atcache_cache_index(list, node, index); return !!node; }
static void list_atcache_check(list_t *list) { if (list->atcache.taildirt > 0 && list->atcache.headdirt == 0) { size_t index = list->length - (list->atcache.taildirt + 1); if (index >= list->atcache.size) { list_atcache_thrash(list); return; } for (size_t i = index; i < list->atcache.taildirt; i++) list->atcache.data[index] = NULL; return; } /* thrash it all */ if (list->atcache.headdirt > 0) list_atcache_thrash(list); }
void *list_search(list_t *list, bool (*predicate)(const void *, const void *), const void *pass) { list_node_t *node = list->head; list_atcache_thrash(list); for(size_t index = 0; node && !predicate(node->element, pass); node = node->next, index++) list_atcache_cache_index(list, node, index); return (node) ? node->element : NULL; }
bool list_erase(list_t *list, void *element) { for (list_node_t *curr = list->head; curr; curr = curr->next) { if (curr->element != element) continue; if (curr == list->head) list->head = list->head->next; if (curr == list->tail) list->tail = list->tail->prev; if (curr->next) curr->next->prev = curr->prev; if (curr->prev) curr->prev->next = curr->next; list_node_destroy(curr); list->length--; list_atcache_thrash(list); return true; } return false; }
void list_sort(list_t *list, bool (*predicate)(const void *, const void *)) { list->head = list_sort_impl(list->head, predicate); list_atcache_thrash(list); }
void list_clear(list_t *list) { while (list->length != 0) list_pop(list); list_atcache_thrash(list); }