comparison th_datastruct.c @ 689:9c61834c191b

Remove th_llist_delete() and th_llist_delete_node() and rename th_llist_delete_node_fast() to th_llist_delete_node().
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Mar 2020 15:20:49 +0200
parents b383f4e6ab89
children 4ca6a3b30fe8
comparison
equal deleted inserted replaced
688:a54298eef91a 689:9c61834c191b
153 153
154 list <- list -> NULL 154 list <- list -> NULL
155 155
156 156
157 */ 157 */
158 void th_llist_delete_node_fast(th_llist_t **list, th_llist_t *node) 158 void th_llist_delete_node(th_llist_t **list, th_llist_t *node)
159 { 159 {
160 if (node == *list) 160 if (node == *list)
161 { 161 {
162 // First node in list 162 // First node in list
163 th_llist_t *tmp = (*list)->next; 163 th_llist_t *tmp = (*list)->next;
184 184
185 node->next = node->prev = NULL; 185 node->next = node->prev = NULL;
186 } 186 }
187 187
188 188
189 void th_llist_delete_node(th_llist_t **list, th_llist_t *node)
190 {
191 th_llist_t *curr = *list;
192
193 while (curr != NULL)
194 {
195 th_llist_t *next = curr->next;
196 if (curr == node)
197 {
198 th_llist_delete_node_fast(list, curr);
199 th_free(node);
200 break;
201 }
202 curr = next;
203 }
204 }
205
206
207 void th_llist_delete(th_llist_t **list, const void *data)
208 {
209 th_llist_t *curr = *list;
210
211 while (curr != NULL)
212 {
213 th_llist_t *next = curr->next;
214 if (curr->data == data)
215 {
216 th_llist_delete_node_fast(list, curr);
217 th_free(curr);
218 break;
219 }
220 curr = next;
221 }
222 }
223
224
225 th_llist_t * th_llist_get_nth(th_llist_t *list, const size_t n) 189 th_llist_t * th_llist_get_nth(th_llist_t *list, const size_t n)
226 { 190 {
227 th_llist_t *curr = list; 191 th_llist_t *curr = list;
228 size_t i; 192 size_t i;
229 193