Lines Matching refs:list

20 static list_node_t *list_free_node_(list_t *list, list_node_t *node);
25 list_t *list = (list_t *)zeroed_allocator->alloc(sizeof(list_t)); in list_new_internal() local
26 if (!list) in list_new_internal()
29 list->free_cb = callback; in list_new_internal()
30 list->allocator = zeroed_allocator; in list_new_internal()
31 return list; in list_new_internal()
38 void list_free(list_t *list) { in list_free() argument
39 if (!list) 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 assert(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 assert(list != NULL); in list_contains()
55 for (const list_node_t *node = list_begin(list); node != list_end(list); node = list_next(node)) { in list_contains()
63 size_t list_length(const list_t *list) { in list_length() argument
64 assert(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 assert(list != NULL); in list_front()
70 assert(!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 assert(list != NULL); in list_back()
77 assert(!list_is_empty(list)); in list_back()
79 return list->tail->data; in list_back()
82 bool list_insert_after(list_t *list, list_node_t *prev_node, void *data) { in list_insert_after() argument
83 assert(list != NULL); in list_insert_after()
87 list_node_t *node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t)); in list_insert_after()
94 if (list->tail == prev_node) in list_insert_after()
95 list->tail = node; in list_insert_after()
96 ++list->length; in list_insert_after()
100 bool list_prepend(list_t *list, void *data) { in list_prepend() argument
101 assert(list != NULL); in list_prepend()
104 list_node_t *node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t)); in list_prepend()
107 node->next = list->head; in list_prepend()
109 list->head = node; in list_prepend()
110 if (list->tail == NULL) in list_prepend()
111 list->tail = list->head; in list_prepend()
112 ++list->length; in list_prepend()
116 bool list_append(list_t *list, void *data) { in list_append() argument
117 assert(list != NULL); in list_append()
120 list_node_t *node = (list_node_t *)list->allocator->alloc(sizeof(list_node_t)); in list_append()
125 if (list->tail == NULL) { in list_append()
126 list->head = node; in list_append()
127 list->tail = node; in list_append()
129 list->tail->next = node; in list_append()
130 list->tail = node; in list_append()
132 ++list->length; in list_append()
136 bool list_remove(list_t *list, void *data) { in list_remove() argument
137 assert(list != NULL); in list_remove()
140 if (list_is_empty(list)) in list_remove()
143 if (list->head->data == data) { in list_remove()
144 list_node_t *next = list_free_node_(list, list->head); in list_remove()
145 if (list->tail == list->head) in list_remove()
146 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; prev = node, node = node->nex… in list_remove()
153 prev->next = list_free_node_(list, node); in list_remove()
154 if (list->tail == node) in list_remove()
155 list->tail = prev; in list_remove()
162 void list_clear(list_t *list) { in list_clear() argument
163 assert(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 void list_foreach(const list_t *list, list_iter_cb callback) { in list_foreach() argument
172 assert(list != NULL); in list_foreach()
175 for (list_node_t *node = list->head; node; ) { in list_foreach()
182 list_node_t *list_begin(const list_t *list) { in list_begin() argument
183 assert(list != NULL); in list_begin()
184 return list->head; in list_begin()
187 list_node_t *list_end(UNUSED_ATTR const list_t *list) { in list_end() argument
188 assert(list != NULL); in list_end()
202 static list_node_t *list_free_node_(list_t *list, list_node_t *node) { in list_free_node_() argument
203 assert(list != NULL); in list_free_node_()
208 if (list->free_cb) in list_free_node_()
209 list->free_cb(node->data); in list_free_node_()
210 list->allocator->free(node); in list_free_node_()
211 --list->length; in list_free_node_()