PULSAR  0.1
Parallel Unified Linear Algebra with Systolic Arrays
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
icl_list.c
Go to the documentation of this file.
1 
12 #include <stdio.h>
13 #include <stdlib.h>
14 
15 #include "icl_list.h"
16 
18 
24 {
25  icl_list_t *node;
26 
27  node = (icl_list_t*)malloc(sizeof(icl_list_t));
28  if (!node)
29  return NULL;
30 
31  node->flink = NULL;
32  node->blink = node;
33  node->data = NULL;
34 
35  return(node);
36 }
37 
39 
50 {
51  icl_list_t *node;
52 
53  if(!head || !pos)
54  return NULL;
55 
56  node = (icl_list_t*)malloc(sizeof(icl_list_t));
57  if (!node)
58  return NULL;
59 
60  node->blink = pos;
61  node->flink = pos->flink;
62  node->data = data;
63 
64  if (pos->flink)
65  pos->flink->blink = node;
66  else
67  head->blink = node; /* node at end of list */
68 
69  pos->flink = node;
70  return node;
71 }
72 
74 
84  icl_list_t *head, icl_list_t *pos, void (*free_function)(void *))
85 {
86  if (!pos || !head)
87  return -1;
88  if (pos == head)
89  return -1;
90 
91  if (free_function && pos->data)
92  (*free_function)(pos->data);
93 
94  pos->blink->flink = pos->flink;
95 
96  if (pos->flink)
97  pos->flink->blink = pos->blink;
98  else
99  head->blink = pos->blink; /* pos at end of list */
100 
101  free(pos);
102  return 0;
103 }
104 
106 
116  icl_list_t *head, void *data, int (*compare)(void*, void*))
117 {
118  icl_list_t *node;
119 
120  if (!head)
121  return NULL;
122 
123  for (node = head->flink; node != NULL; node = node->flink) {
124  if (!node->data)
125  continue;
126  if ((compare && (*compare)(node->data, data) == 0))
127  break;
128  else if (node->data == data)
129  break; /* compare == NULL, then direct comparison of pointers */
130  }
131  return(node);
132 }
133 
135 
143 int
144 icl_list_destroy(icl_list_t *head, void (*free_function)(void*))
145 {
146  icl_list_t *node, *tmpnode;
147 
148  if (!head)
149  return -1;
150 
151  for (node = head; node != NULL;) {
152  tmpnode = node->flink;
153 
154  if (free_function != NULL && node->data != NULL)
155  (*free_function)(node->data);
156 
157  free(node);
158  node = tmpnode;
159  }
160  return 0;
161 }
162 
164 
172 {
173  int size = 0;
174 
175  if (!head)
176  return -1;
177 
178  while ((head=head->flink))
179  size++;
180 
181  return size;
182 }
183 
185 
193 {
194  if (head)
195  return head->flink;
196 
197  return NULL;
198 }
199 
201 
209 {
210  if (head)
211  return head->blink;
212 
213  return NULL;
214 }
215 
217 
226 {
227  if(pos)
228  return pos->flink;
229 
230  return NULL;
231 }
232 
234 
243 {
244  if (pos && pos->blink != NULL && pos != head &&
245  pos->blink != head && pos->blink != pos)
246  return pos->blink;
247 
248  return NULL;
249 }
250 
252 
262 {
263  if (!head1 || !head2 || !head1->blink || !head2->flink)
264  return NULL;
265 
266  head1->blink->flink = head2->flink;
267  head2->flink->blink = head1->blink;
268  head1->blink = head2->blink;
269 
270  free(head2);
271  return(head1);
272 }
273 
275 
284 {
285  return (icl_list_insert(head, head, data));
286 }
287 
289 
298 {
299  return (icl_list_insert(head, head->blink, data));
300 }
icl_list_t * icl_list_search(icl_list_t *head, void *data, int(*compare)(void *, void *))
Finds a data item in the specified linked list.
Definition: icl_list.c:115
icl_list_t * icl_list_prepend(icl_list_t *head, void *data)
Insert a node at the beginning of this list.
Definition: icl_list.c:283
icl_list_t * icl_list_new()
Create new linked list.
Definition: icl_list.c:23
int icl_list_size(icl_list_t *head)
Get the number of items in this linked list.
Definition: icl_list.c:171
void * data
Definition: icl_list.h:20
int icl_list_destroy(icl_list_t *head, void(*free_function)(void *))
Frees the resources associated with this linked list.
Definition: icl_list.c:144
icl_list_t * icl_list_append(icl_list_t *head, void *data)
Insert a node at the end of this list.
Definition: icl_list.c:297
dependency free linked list
icl_list_t * icl_list_last(icl_list_t *head)
Get the last item in this linked list.
Definition: icl_list.c:208
icl_list_t * icl_list_first(icl_list_t *head)
Get the first item in this linked list.
Definition: icl_list.c:192
icl_list_t * icl_list_prev(icl_list_t *head, icl_list_t *pos)
Get the node preceding the specified node.
Definition: icl_list.c:242
icl_list_t * icl_list_concat(icl_list_t *head1, icl_list_t *head2)
Concatenate two linked lists.
Definition: icl_list.c:261
int icl_list_delete(icl_list_t *head, icl_list_t *pos, void(*free_function)(void *))
Delete the specified node.
Definition: icl_list.c:83
icl_list_t * icl_list_insert(icl_list_t *head, icl_list_t *pos, void *data)
Insert a new node after the specified node.
Definition: icl_list.c:49
struct icl_list_s * blink
Definition: icl_list.h:22
struct icl_list_s * flink
Definition: icl_list.h:21
icl_list_t * icl_list_next(icl_list_t *head, icl_list_t *pos)
Get the node following the specified node.
Definition: icl_list.c:225