PULSAR  0.1
Parallel Unified Linear Algebra with Systolic Arrays
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
icl_list.h File Reference

dependency free linked list More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  icl_list_s
 

Macros

#define icl_list_foreach(list, ptr)   for (ptr = icl_list_first(list); ptr != NULL; ptr = icl_list_next(list, ptr))
 

Typedefs

typedef struct icl_list_s icl_list_t
 

Functions

icl_list_ticl_list_new ()
 Create new linked list. More...
 
icl_list_ticl_list_insert (icl_list_t *, icl_list_t *, void *)
 Insert a new node after the specified node. More...
 
icl_list_ticl_list_search (icl_list_t *, void *, int(*)(void *, void *))
 Finds a data item in the specified linked list. More...
 
icl_list_ticl_list_first (icl_list_t *)
 Get the first item in this linked list. More...
 
icl_list_ticl_list_last (icl_list_t *)
 Get the last item in this linked list. More...
 
icl_list_ticl_list_next (icl_list_t *, icl_list_t *)
 Get the node following the specified node. More...
 
icl_list_ticl_list_prev (icl_list_t *, icl_list_t *)
 Get the node preceding the specified node. More...
 
icl_list_ticl_list_concat (icl_list_t *, icl_list_t *)
 Concatenate two linked lists. More...
 
icl_list_ticl_list_prepend (icl_list_t *, void *)
 Insert a node at the beginning of this list. More...
 
icl_list_ticl_list_append (icl_list_t *, void *)
 Insert a node at the end of this list. More...
 
int icl_list_delete (icl_list_t *, icl_list_t *, void(*)(void *))
 Delete the specified node. More...
 
int icl_list_destroy (icl_list_t *, void(*)(void *))
 Frees the resources associated with this linked list. More...
 
int icl_list_size (icl_list_t *)
 Get the number of items in this linked list. More...
 

Detailed Description

dependency free linked list

Author
Keith Seymour
Jakub Kurzak

PULSAR Runtime /pulsar/ Copyright (C) 2012-2013 University of Tennessee.

Definition in file icl_list.h.

Macro Definition Documentation

#define icl_list_foreach (   list,
  ptr 
)    for (ptr = icl_list_first(list); ptr != NULL; ptr = icl_list_next(list, ptr))

Definition at line 40 of file icl_list.h.

Typedef Documentation

typedef struct icl_list_s icl_list_t

Function Documentation

icl_list_t* icl_list_append ( icl_list_t head,
void *  data 
)

Insert a node at the end of this list.

Parameters
head– the linked list
data– the data to be inserted
Returns
pointer to the new node. returns NULL on error.

Definition at line 297 of file icl_list.c.

References icl_list_s::blink, and icl_list_insert().

298 {
299  return (icl_list_insert(head, head->blink, data));
300 }
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

Here is the call graph for this function:

Here is the caller graph for this function:

icl_list_t* icl_list_concat ( icl_list_t head1,
icl_list_t head2 
)

Concatenate two linked lists.

Parameters
head1– the first linked list
head2– the second linked list
Returns
pointer to the new linked list, which consists of <head1,head2>. returns NULL on error.

Definition at line 261 of file icl_list.c.

References icl_list_s::blink, and icl_list_s::flink.

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 }
struct icl_list_s * blink
Definition: icl_list.h:22
struct icl_list_s * flink
Definition: icl_list.h:21
int icl_list_delete ( icl_list_t head,
icl_list_t pos,
void(*)(void *)  free_function 
)

Delete the specified node.

Parameters
head– the linked list containing the node to be deleted
pos– the node to be deleted
free_function– pointer to function that frees the node data
Returns
0 on success, -1 on failure.

Definition at line 83 of file icl_list.c.

References icl_list_s::blink, icl_list_s::data, and icl_list_s::flink.

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 }
void * data
Definition: icl_list.h:20
struct icl_list_s * blink
Definition: icl_list.h:22
struct icl_list_s * flink
Definition: icl_list.h:21

Here is the caller graph for this function:

int icl_list_destroy ( icl_list_t head,
void(*)(void *)  free_function 
)

Frees the resources associated with this linked list.

Parameters
head– the linked list to be destroyed
free_function– pointer to function that frees the node's data
Returns
0 on success, -1 on failure.

Definition at line 144 of file icl_list.c.

References icl_list_s::data, and icl_list_s::flink.

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 }
void * data
Definition: icl_list.h:20
struct icl_list_s * flink
Definition: icl_list.h:21

Here is the caller graph for this function:

icl_list_t* icl_list_first ( icl_list_t head)

Get the first item in this linked list.

Parameters
head– the linked list
Returns
pointer to the first item. returns NULL on error.

Definition at line 192 of file icl_list.c.

References icl_list_s::flink.

193 {
194  if (head)
195  return head->flink;
196 
197  return NULL;
198 }
struct icl_list_s * flink
Definition: icl_list.h:21

Here is the caller graph for this function:

icl_list_t* icl_list_insert ( icl_list_t head,
icl_list_t pos,
void *  data 
)

Insert a new node after the specified node.

Parameters
head– the linked list
pos– points to the position of the new node (it will be inserted after this node)
data– pointer to the data that is to be inserted
Returns
pointer to the new node. returns NULL on error.

Definition at line 49 of file icl_list.c.

References icl_list_s::blink, icl_list_s::data, and icl_list_s::flink.

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 }
void * data
Definition: icl_list.h:20
struct icl_list_s * blink
Definition: icl_list.h:22
struct icl_list_s * flink
Definition: icl_list.h:21

Here is the caller graph for this function:

icl_list_t* icl_list_last ( icl_list_t head)

Get the last item in this linked list.

Parameters
head– the linked list
Returns
pointer to the last item. returns NULL on error.

Definition at line 208 of file icl_list.c.

References icl_list_s::blink.

209 {
210  if (head)
211  return head->blink;
212 
213  return NULL;
214 }
struct icl_list_s * blink
Definition: icl_list.h:22
icl_list_t* icl_list_new ( )

Create new linked list.

Returns
pointer to new linked list. returns NULL on error.

Definition at line 23 of file icl_list.c.

References icl_list_s::blink, icl_list_s::data, and icl_list_s::flink.

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 }
void * data
Definition: icl_list.h:20
struct icl_list_s * blink
Definition: icl_list.h:22
struct icl_list_s * flink
Definition: icl_list.h:21

Here is the caller graph for this function:

icl_list_t* icl_list_next ( icl_list_t head,
icl_list_t pos 
)

Get the node following the specified node.

Parameters
head– the list containing the specified node
pos– the node whose successor should be returned
Returns
pointer to the next node. returns NULL on error.

Definition at line 225 of file icl_list.c.

References icl_list_s::flink.

226 {
227  if(pos)
228  return pos->flink;
229 
230  return NULL;
231 }
struct icl_list_s * flink
Definition: icl_list.h:21

Here is the caller graph for this function:

icl_list_t* icl_list_prepend ( icl_list_t head,
void *  data 
)

Insert a node at the beginning of this list.

Parameters
head– the linked list
data– the data to be inserted
Returns
pointer to the new node. returns NULL on error.

Definition at line 283 of file icl_list.c.

References icl_list_insert().

284 {
285  return (icl_list_insert(head, head, data));
286 }
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

Here is the call graph for this function:

Here is the caller graph for this function:

icl_list_t* icl_list_prev ( icl_list_t head,
icl_list_t pos 
)

Get the node preceding the specified node.

Parameters
head– the list containing the specified node
pos– the node whose predecessor should be returned
Returns
pointer to the previous node. returns NULL on error.

Definition at line 242 of file icl_list.c.

References icl_list_s::blink.

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 }
struct icl_list_s * blink
Definition: icl_list.h:22
icl_list_t* icl_list_search ( icl_list_t head,
void *  data,
int(*)(void *, void *)  compare 
)

Finds a data item in the specified linked list.

Parameters
head– the linked list
data– the data to be found
compare– function that compares the data items
Returns
pointer to the node, if found. otherwise returns NULL.

Definition at line 115 of file icl_list.c.

References icl_list_s::data, and icl_list_s::flink.

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 }
void * data
Definition: icl_list.h:20
struct icl_list_s * flink
Definition: icl_list.h:21

Here is the caller graph for this function:

int icl_list_size ( icl_list_t head)

Get the number of items in this linked list.

Parameters
head– the linked list
Returns
the number of items in the list. returns -1 on error.

Definition at line 171 of file icl_list.c.

References icl_list_s::flink.

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 }
struct icl_list_s * flink
Definition: icl_list.h:21

Here is the caller graph for this function: