5 #ifdef LL_IS_ARRAY_BACKED 9 list->backingArray[i].data=0;
10 list->backingArray[i].inUse=0;
11 list->backingArray[i].next=0;
12 list->backingArray[i].prev=0;
13 list->backingArray[i].parentList = list;
16 list->head.parentList = list;
19 list->tail.parentList = list;
25 list->head.prev = &list->tail;
29 list->tail.prev = &list->head;
32 list->insertCompFunc = 0;
33 list->freeNodeFunc = 0;
34 list->searchCompFunc = 0;
39 #ifdef LL_IS_ARRAY_BACKED 43 if(!list->backingArray[i].inUse)
45 list->backingArray[i].inUse = 1;
46 list->numNodesInUse++;
47 list->backingArray[i].data = data;
48 return &(list->backingArray[i]);
65 list->insertCompFunc = newCompFunc;
70 list->freeNodeFunc = newFreeFunc;
75 list->searchCompFunc = newSearchFunc;
80 #ifdef LL_IS_ARRAY_BACKED 81 if(preceedingNode->parentList != newNode->parentList)
90 newNode->next = preceedingNode->next;
91 newNode->prev = preceedingNode;
93 newNode->next->prev = newNode;
94 newNode->prev->next = newNode;
101 #ifdef LL_IS_ARRAY_BACKED 102 if(nodeToFollow->parentList != newNode->parentList)
111 newNode->next = nodeToFollow;
112 newNode->prev = nodeToFollow->prev;
114 newNode->next->prev = newNode;
115 newNode->prev->next = newNode;
124 if(nodeToRemove->prev){nodeToRemove->prev->next = nodeToRemove->next;}
125 if(nodeToRemove->next){nodeToRemove->next->prev = nodeToRemove->prev;}
126 nodeToRemove->next = 0;
127 nodeToRemove->prev = 0;
134 #ifdef LL_IS_ARRAY_BACKED 143 if(nodeToMove->parentList->freeNodeFunc)
145 (*(nodeToMove->parentList->freeNodeFunc))(nodeToMove);
147 return newNodeInList;
156 int (*compFunctCpy)(
void*,
void*) = (listToSearch->searchCompFunc) ?
157 listToSearch->searchCompFunc :
158 listToSearch->insertCompFunc;
161 node_t * itNode = listToSearch->head.next;
162 for(; itNode != &(listToSearch->tail); itNode = itNode->next)
164 if(!(*(compFunctCpy))(itNode->data, data))
181 #ifdef LL_IS_ARRAY_BACKED 182 if(newNode->parentList != list)
190 if(list->insertCompFunc)
192 node_t * itNode = list->head.next;
193 for(; itNode != &(list->tail); itNode = itNode->next)
195 int result = ((*(list->insertCompFunc))(itNode->data, newNode->data));
209 list->printNodeFunc = newPrintFunc;
214 if(list->printNodeFunc)
216 node_t * itNode = list->head.next;
217 if(itNode == &(list->tail))
219 printf(
"%s",
"<List is Empty>\r\n");
221 for(; itNode != &(list->tail); itNode = itNode->next)
223 list->printNodeFunc(itNode->data);
227 printf(
"No Search Function provided for List!%s\r\n",
" ");
234 (void)nodeData1; (void)nodeData2;
240 return strcmp((
const char*)(nodeData1), (
const char*)(nodeData2));
247 printf(
"List Test Print: data is string: %s\r\n", (
const char*)nodeData);
275 printf(
"looking for node whose data is: %s\r\nsearch return: %d\r\n",
"test5", (
int)nodeFound);
279 printf(
"found node:: data string = %s\r\n", (
const char*)nodeFound->data);
void setInsertComparisonFunction(linkedList_t *list, int(*newCompFunc)(void *, void *))
takes in a function pointer and sets the library shared comparison pointer
void * sys_alloc_mem(u32int size)
node_t * insertAfterNode(node_t *preceedingNode, node_t *newNode)
insert a node into the parent list of the preceedingNode after preceedingNode
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.
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...
node_t * insertBeforeNode(node_t *nodeToFollow, node_t *newNode)
insert a node into the parent list of the nodeToFollow before nodeToFollow
int searchcompFunction(void *nodeData1, void *nodeData2)
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
void setFreeFunction(linkedList_t *list, int(*newFreeFunc)(node_t *))
sets the function whose job it is to free the node's memory
typedef of linked list (see s_ll).
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
void testPrintFunc(void *nodeData)
int compFunction(void *nodeData1, void *nodeData2)
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.
node_t * searchList(linkedList_t *listToSearch, void *data)
goes through the list using the list's comparison function to find the node which matches the data...
node_t * removeNode(node_t *nodeToRemove)
will remove the node from the list. the list hierarchy will change to reflect the missing node...
void initLinkedList(linkedList_t *list)
initilize list and the optional array that backs the list
#define MAX_NUM_OF_LL_NODES
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
void listTest()
test the linked_list class with const char* data and output to screen the results of the test ...
node_t * insertNode(linkedList_t *list, node_t *newNode)
Will insert the node into the list. This function will attempt to call the list's insert comparison f...
node_t * makeNewNode(linkedList_t *list, void *data)
get new node, allocate a new node or find an unused node from the list's pool