impl free node,destroy

This commit is contained in:
Gregory Burd 2024-03-19 12:57:29 -04:00
parent f0e4c84fab
commit ef30d16d62
2 changed files with 22 additions and 6 deletions

View file

@ -133,6 +133,8 @@ main()
api_skip_dot_slex(of, list, sprintf_slex_node);
fclose(of);
api_skip_destroy_slex(list);
#if 0
/* Delete a specific element in the list. */
struct slex_node query;

View file

@ -210,7 +210,7 @@
void prefix##skip_free_node_##decl(decl##_node_t *node) \
{ \
free_node_blk; \
free(node->field.sle_next); \
ARRAY_FREE(node->field.sle_next); \
free(node); \
} \
\
@ -229,13 +229,13 @@
/* -- skip_head_ */ \
decl##_node_t *prefix##skip_head_##decl(decl##_t *slist) \
{ \
return slist->slh_head; \
return slist->slh_head->field.sle_next[0]; \
} \
\
/* -- skip_tail_ */ \
decl##_node_t *prefix##skip_tail_##decl(decl##_t *slist) \
{ \
return slist->slh_tail; \
return slist->slh_tail->field.sle_prev; \
} \
\
/* -- skip_locate_ */ \
@ -446,10 +446,24 @@
} \
\
/* -- skip_destroy_ */ \
int prefix##skip_destroy_##decl(decl##_t *slist, decl##_node_t *n) \
int prefix##skip_destroy_##decl(decl##_t *slist) \
{ \
((void)slist); /* TODO */ \
((void)n); \
decl##_node_t *node, *next; \
if (!slist) \
return 0; \
if (prefix##skip_size_##decl(slist) == 0) \
return 0; \
node = prefix##skip_head_##decl(slist); \
do { \
next = prefix##skip_next_node_##decl(slist, node); \
prefix##skip_free_node_##decl(node); \
node = next; \
} while (node != NULL); \
\
ARRAY_FREE(slist->slh_head->field.sle_next); \
free(slist->slh_head); \
ARRAY_FREE(slist->slh_tail->field.sle_next); \
free(slist->slh_tail); \
return 0; \
} \
\