Lines Matching refs:list

20 static list_node_t* list_free_node_(list_t* list, list_node_t* node);
27 list_t* list = (list_t*)zeroed_allocator->alloc(sizeof(list_t)); in list_new_internal() local
28 if (!list) return NULL; in list_new_internal()
30 list->free_cb = callback; in list_new_internal()
31 list->allocator = zeroed_allocator; in list_new_internal()
32 return list; in list_new_internal()
39 void list_free(list_t* list) { in list_free() argument
40 if (!list) return; in list_free()
42 list_clear(list); in list_free()
43 list->allocator->free(list); in list_free()
46 bool list_is_empty(const list_t* list) { in list_is_empty() argument
47 CHECK(list != NULL); in list_is_empty()
48 return (list->length == 0); in list_is_empty()
51 bool list_contains(const list_t* list, const void* data) { in list_contains() argument
52 CHECK(list != NULL); in list_contains()
55 for (const list_node_t* node = list_begin(list); node != list_end(list); in list_contains()
63 size_t list_length(const list_t* list) { in list_length() argument
64 CHECK(list != NULL); in list_length()
65 return list->length; in list_length()
68 void* list_front(const list_t* list) { in list_front() argument
69 CHECK(list != NULL); in list_front()
70 CHECK(!list_is_empty(list)); in list_front()
72 return list->head->data; in list_front()
75 void* list_back(const list_t* list) { in list_back() argument
76 CHECK(list != NULL); in list_back()
77 CHECK(!list_is_empty(list)); in list_back()
79 return list->tail->data; in list_back()
82 list_node_t* list_back_node(const list_t* list) { in list_back_node() argument
83 CHECK(list != NULL); in list_back_node()
84 CHECK(!list_is_empty(list)); in list_back_node()
86 return list->tail; in list_back_node()
89 bool list_insert_after(list_t* list, list_node_t* prev_node, void* data) { in list_insert_after() argument
90 CHECK(list != NULL); in list_insert_after()
94 list_node_t* node = (list_node_t*)list->allocator->alloc(sizeof(list_node_t)); in list_insert_after()
100 if (list->tail == prev_node) list->tail = node; in list_insert_after()
101 ++list->length; in list_insert_after()
105 bool list_prepend(list_t* list, void* data) { in list_prepend() argument
106 CHECK(list != NULL); in list_prepend()
109 list_node_t* node = (list_node_t*)list->allocator->alloc(sizeof(list_node_t)); in list_prepend()
111 node->next = list->head; in list_prepend()
113 list->head = node; in list_prepend()
114 if (list->tail == NULL) list->tail = list->head; in list_prepend()
115 ++list->length; in list_prepend()
119 bool list_append(list_t* list, void* data) { in list_append() argument
120 CHECK(list != NULL); in list_append()
123 list_node_t* node = (list_node_t*)list->allocator->alloc(sizeof(list_node_t)); in list_append()
127 if (list->tail == NULL) { in list_append()
128 list->head = node; in list_append()
129 list->tail = node; in list_append()
131 list->tail->next = node; in list_append()
132 list->tail = node; in list_append()
134 ++list->length; in list_append()
138 bool list_remove(list_t* list, void* data) { in list_remove() argument
139 CHECK(list != NULL); in list_remove()
142 if (list_is_empty(list)) return false; in list_remove()
144 if (list->head->data == data) { in list_remove()
145 list_node_t* next = list_free_node_(list, list->head); in list_remove()
146 if (list->tail == list->head) list->tail = next; in list_remove()
147 list->head = next; in list_remove()
151 for (list_node_t *prev = list->head, *node = list->head->next; node; in list_remove()
154 prev->next = list_free_node_(list, node); in list_remove()
155 if (list->tail == node) list->tail = prev; in list_remove()
162 void list_clear(list_t* list) { in list_clear() argument
163 CHECK(list != NULL); in list_clear()
164 for (list_node_t* node = list->head; node;) in list_clear()
165 node = list_free_node_(list, node); in list_clear()
166 list->head = NULL; in list_clear()
167 list->tail = NULL; in list_clear()
168 list->length = 0; in list_clear()
171 list_node_t* list_foreach(const list_t* list, list_iter_cb callback, in list_foreach() argument
173 CHECK(list != NULL); in list_foreach()
176 for (list_node_t* node = list->head; node;) { in list_foreach()
184 list_node_t* list_begin(const list_t* list) { in list_begin() argument
185 CHECK(list != NULL); in list_begin()
186 return list->head; in list_begin()
189 list_node_t* list_end(UNUSED_ATTR const list_t* list) { in list_end() argument
190 CHECK(list != NULL); in list_end()
204 static list_node_t* list_free_node_(list_t* list, list_node_t* node) { in list_free_node_() argument
205 CHECK(list != NULL); in list_free_node_()
210 if (list->free_cb) list->free_cb(node->data); in list_free_node_()
211 list->allocator->free(node); in list_free_node_()
212 --list->length; in list_free_node_()