| 1 | #include "prism/util/pm_list.h" |
| 2 | |
| 3 | /** |
| 4 | * Returns true if the given list is empty. |
| 5 | */ |
| 6 | PRISM_EXPORTED_FUNCTION bool |
| 7 | pm_list_empty_p(pm_list_t *list) { |
| 8 | return list->head == NULL; |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * Returns the size of the list. |
| 13 | */ |
| 14 | PRISM_EXPORTED_FUNCTION size_t |
| 15 | pm_list_size(pm_list_t *list) { |
| 16 | return list->size; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Append a node to the given list. |
| 21 | */ |
| 22 | void |
| 23 | pm_list_append(pm_list_t *list, pm_list_node_t *node) { |
| 24 | if (list->head == NULL) { |
| 25 | list->head = node; |
| 26 | } else { |
| 27 | list->tail->next = node; |
| 28 | } |
| 29 | |
| 30 | list->tail = node; |
| 31 | list->size++; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Deallocate the internal state of the given list. |
| 36 | */ |
| 37 | PRISM_EXPORTED_FUNCTION void |
| 38 | pm_list_free(pm_list_t *list) { |
| 39 | pm_list_node_t *node = list->head; |
| 40 | pm_list_node_t *next; |
| 41 | |
| 42 | while (node != NULL) { |
| 43 | next = node->next; |
| 44 | xfree(node); |
| 45 | node = next; |
| 46 | } |
| 47 | |
| 48 | list->size = 0; |
| 49 | } |