4 * An abstract linked list.
9 #include "prism/defines.h"
17 * This struct represents an abstract linked list that provides common
18 * functionality. It is meant to be used any time a linked list is necessary to
21 * The linked list itself operates off a set of pointers. Because the pointers
22 * are not necessarily sequential, they can be of any size. We use this fact to
23 * allow the consumer of this linked list to extend the node struct to include
24 * any data they want. This is done by using the pm_list_node_t as the first
25 * member of the struct.
27 * For example, if we want to store a list of integers, we can do the following:
31 * pm_list_node_t node;
35 * pm_list_t list = { 0 };
36 * pm_int_node_t *node = xmalloc(sizeof(pm_int_node_t));
39 * pm_list_append(&list, &node->node);
42 * The pm_list_t struct is used to represent the overall linked list. It
43 * contains a pointer to the head and tail of the list. This allows for easy
44 * iteration and appending of new nodes.
46 typedef struct pm_list_node
{
47 /** A pointer to the next node in the list. */
48 struct pm_list_node
*next
;
52 * This represents the overall linked list. It keeps a pointer to the head and
53 * tail so that iteration is easy and pushing new nodes is easy.
56 /** The size of the list. */
59 /** A pointer to the head of the list. */
62 /** A pointer to the tail of the list. */
67 * Returns true if the given list is empty.
69 * @param list The list to check.
70 * @return True if the given list is empty, otherwise false.
72 PRISM_EXPORTED_FUNCTION
bool pm_list_empty_p(pm_list_t
*list
);
75 * Returns the size of the list.
77 * @param list The list to check.
78 * @return The size of the list.
80 PRISM_EXPORTED_FUNCTION
size_t pm_list_size(pm_list_t
*list
);
83 * Append a node to the given list.
85 * @param list The list to append to.
86 * @param node The node to append.
88 void pm_list_append(pm_list_t
*list
, pm_list_node_t
*node
);
91 * Deallocate the internal state of the given list.
93 * @param list The list to free.
95 PRISM_EXPORTED_FUNCTION
void pm_list_free(pm_list_t
*list
);