Home | History | Annotate | Download | only in src

Lines Matching refs:list

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