Modestus Moon OS  R4
CS 450 project
linked_list.h
Go to the documentation of this file.
1 
9 #ifndef LINKEDLIST_H
10 #define LINKEDLIST_H
11 
12 #include "string.h"
13 
14 
15 //#define LL_IS_ARRAY_BACKED 1 //this defines if the linked list is back by an array of constant size or dynamically allocated
16 
17 #ifndef LL_IS_ARRAY_BACKED
18 #include <core/mpx_supt.h> //if the list is dynamically allocated, then we need the allocation functions from the core.
19 #endif
20 
21 //maximum number of nodes if the list is array backed.
22 #define MAX_NUM_OF_LL_NODES 256
23 
30 typedef struct s_ll linkedList_t;
31 
38 typedef struct s_ll_node node_t;
39 
46 struct s_ll_node
47 {
48  void *data;
51 #ifdef LL_IS_ARRAY_BACKED
52  linkedList_t *parentList;
53  unsigned char inUse;
54 #endif
55 };
56 
62 struct s_ll
63 {
66  int (*searchCompFunc)(void*, void*);
67  int (*insertCompFunc)(void*, void*);
68  int (*freeNodeFunc)(node_t *nodeToFree);
69  void (*printNodeFunc)(void*);
70  size_t length;
71 #ifdef LL_IS_ARRAY_BACKED
72  unsigned int numNodesInUse;
73  node_t backingArray[MAX_NUM_OF_LL_NODES];
74 #endif
75 };
76 
81 #define VARIABLE_LL_LENGTH(LIST_LENGTH) { \
82  typedef struct s_ll_##LIST_LENGTH##_t linkedList_##LIST_LENGTH##_t \
83  struct s_ll_##LIST_LENGTH##_t \
84  { \
85  node_t head; \
86  node_t tail; \
87  int (*searchCompFunc)(void*, void*); \
88  int (*comparisonFunc)(void*, void*); \
89  int (*freeNodeFunc)(node_t *nodeToFree); \
90  void (*printList)(void*); \
91  size_t length; \
92  unsigned int numNodesInUse; \
93  node_t backingArray[LIST_LENGTH]; \
94  }; \
95 }
96 
97 
102 void initLinkedList(linkedList_t *list);
103 
104 
111 node_t * insertAfterNode(node_t *preceedingNode, node_t * newNode);
112 
119 node_t * insertBeforeNode(node_t * nodeToFollow, node_t *newNode);
120 
129 node_t * insertNode(linkedList_t *list, node_t * newNode);
130 
131 
138 node_t *makeNewNode(linkedList_t *list, void *data);
139 
153 node_t * moveNodeToNewList(node_t *nodeToMove, linkedList_t *newList);
154 
155 
161 void setFreeFunction(linkedList_t *list, int (*newFreeFunc)(node_t *));
162 
172 void setInsertComparisonFunction(linkedList_t* list, int (*newCompFunc)(void*, void*));
173 
182 void setPrintFunction(linkedList_t *list, void (*newPrintFunc)(void*));
183 
195 void setSearchComparisonFunction(linkedList_t *list, int (*newSearchFunc)(void*, void*));
196 
197 
198 
204 node_t * removeNode(node_t *nodeToRemove);
205 
214 node_t *searchList(linkedList_t *listToSearch, void *data);
215 
216 
217 
222 void printList(linkedList_t *list);
223 
228 void listTest();
229 
230 #endif // LINKEDLIST_H
node_t * next
Definition: linked_list.h:49
typedef of linked list node (see s_ll_node).
void setPrintFunction(linkedList_t *list, void(*newPrintFunc)(void *))
sets the function whose job it is to print the list to the screen.
Definition: linked_list.c:207
void * data
Definition: linked_list.h:48
void setSearchComparisonFunction(linkedList_t *list, int(*newSearchFunc)(void *, void *))
sets the function whose job it is to compare the input data with the data in the list. the first void parameter will always be the data contained in the list, the second will be the data passed to the search function.
Definition: linked_list.c:73
node_t * removeNode(node_t *nodeToRemove)
will remove the node from the list. the list hierarchy will change to reflect the missing node...
Definition: linked_list.c:120
void initLinkedList(linkedList_t *list)
initilize list and the optional array that backs the list
Definition: linked_list.c:3
typedef of linked list (see s_ll).
node_t * insertAfterNode(node_t *preceedingNode, node_t *newNode)
insert a node into the parent list of the preceedingNode after preceedingNode
Definition: linked_list.c:78
node_t * moveNodeToNewList(node_t *nodeToMove, linkedList_t *newList)
If a node needs to move lists and lists are array backed, instead of just moving preceeding and sucee...
Definition: linked_list.c:132
size_t length
Definition: linked_list.h:70
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
Definition: linked_list.c:212
node_t * prev
Definition: linked_list.h:50
node_t * makeNewNode(linkedList_t *list, void *data)
get new node, allocate a new node or find an unused node from the list&#39;s pool
Definition: linked_list.c:37
void setInsertComparisonFunction(linkedList_t *list, int(*newCompFunc)(void *, void *))
takes in a function pointer and sets the library shared comparison pointer
Definition: linked_list.c:63
struct definition for the linked list
Definition: linked_list.h:62
node_t tail
Definition: linked_list.h:65
node_t * insertNode(linkedList_t *list, node_t *newNode)
Will insert the node into the list. This function will attempt to call the list&#39;s insert comparison f...
Definition: linked_list.c:173
#define MAX_NUM_OF_LL_NODES
Definition: linked_list.h:22
struct for a node of the linked list
Definition: linked_list.h:46
void setFreeFunction(linkedList_t *list, int(*newFreeFunc)(node_t *))
sets the function whose job it is to free the node&#39;s memory
Definition: linked_list.c:68
node_t * searchList(linkedList_t *listToSearch, void *data)
goes through the list using the list&#39;s comparison function to find the node which matches the data...
Definition: linked_list.c:154
void listTest()
test the linked_list class with const char* data and output to screen the results of the test ...
Definition: linked_list.c:250
node_t head
Definition: linked_list.h:64
node_t * insertBeforeNode(node_t *nodeToFollow, node_t *newNode)
insert a node into the parent list of the nodeToFollow before nodeToFollow
Definition: linked_list.c:99