#include <stdio.h>#include <stdlib.h>#include "icl_list.h"
Go to the source code of this file.
Functions | |
| icl_list_t * | icl_list_new () |
| icl_list_t * | icl_list_insert (icl_list_t *head, icl_list_t *pos, void *data) |
| int | icl_list_delete (icl_list_t *head, icl_list_t *pos, void(*free_function)(void *)) |
| icl_list_t * | icl_list_search (icl_list_t *head, void *data, int(*compare)(void *, void *)) |
| int | icl_list_destroy (icl_list_t *head, void(*free_function)(void *)) |
| int | icl_list_size (icl_list_t *head) |
| icl_list_t * | icl_list_first (icl_list_t *head) |
| icl_list_t * | icl_list_next (icl_list_t *head, icl_list_t *pos) |
| icl_list_t * | icl_list_prev (icl_list_t *head, icl_list_t *pos) |
| icl_list_t * | icl_list_concat (icl_list_t *head1, icl_list_t *head2) |
| icl_list_t * | icl_list_prepend (icl_list_t *head, void *data) |
| icl_list_t * | icl_list_append (icl_list_t *head, void *data) |
Dependency free doubly linked list implementation.
Definition in file icl_list.c.
| icl_list_t* icl_list_append | ( | icl_list_t * | head, | |
| void * | data | |||
| ) |
Insert a node at the end of this list.
| head | -- the linked list | |
| data | -- the data to be inserted |
Definition at line 286 of file icl_list.c.
{
return(icl_list_insert(head, head->blink, data));
}


| icl_list_t* icl_list_concat | ( | icl_list_t * | head1, | |
| icl_list_t * | head2 | |||
| ) |
Concatenate two linked lists.
| head1 | -- the first linked list | |
| head2 | -- the second linked list |
Definition at line 247 of file icl_list.c.
{
if(!head1 || !head2 || !head1->blink || !head2->flink)
return NULL;
head1->blink->flink = head2->flink;
head2->flink->blink = head1->blink;
head1->blink = head2->blink;
free(head2);
return(head1);
}
| int icl_list_delete | ( | icl_list_t * | head, | |
| icl_list_t * | pos, | |||
| void(*)(void *) | free_function | |||
| ) |
Delete the specified node.
| 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 |
Definition at line 84 of file icl_list.c.
{
if (!pos || !head) return -1;
if (pos == head) return -1;
if(free_function && pos->data)
(*free_function)(pos->data);
pos->blink->flink = pos->flink;
if(pos->flink)
pos->flink->blink = pos->blink;
else
head->blink = pos->blink; /* pos at end of list */
free(pos);
return 0;
}

| int icl_list_destroy | ( | icl_list_t * | head, | |
| void(*)(void *) | free_function | |||
| ) |
Frees the resources associated with this linked list.
| head | -- the linked list to be destroyed | |
| free_function | -- pointer to function that frees the node's data |
Definition at line 143 of file icl_list.c.
{
icl_list_t *node, *tmpnode;
if (!head) return -1;
for(node=head; node!=NULL; ) {
tmpnode = node->flink;
if(free_function!=NULL && node->data!=NULL)
(*free_function)(node->data);
free(node);
node = tmpnode;
}
return 0;
}

| icl_list_t* icl_list_first | ( | icl_list_t * | head | ) |
Get the first item in this linked list.
| head | -- the linked list |
Definition at line 192 of file icl_list.c.
{
if(head)
return head->flink;
return NULL;
}

| icl_list_t* icl_list_insert | ( | icl_list_t * | head, | |
| icl_list_t * | pos, | |||
| void * | data | |||
| ) |
Insert a new node after the specified node.
| 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 |
Definition at line 49 of file icl_list.c.
{
icl_list_t *node;
if(!head || !pos) return NULL;
node = (icl_list_t*)malloc(sizeof(icl_list_t));
if(!node) return NULL;
node->blink = pos;
node->flink = pos->flink;
node->data = data;
if(pos->flink)
pos->flink->blink = node;
else
head->blink = node; /* node at end of list */
pos->flink = node;
return node;
}

| icl_list_t* icl_list_new | ( | ) |
Create new linked list.
Definition at line 22 of file icl_list.c.
{
icl_list_t *node;
node = (icl_list_t*)malloc(sizeof(icl_list_t));
if(!node) return NULL;
node->flink = NULL;
node->blink = node;
node->data = NULL;
return(node);
}

| icl_list_t* icl_list_next | ( | icl_list_t * | head, | |
| icl_list_t * | pos | |||
| ) |
Get the node following the specified node.
| head | -- the list containing the specified node | |
| pos | -- the node whose successor should be returned |
Definition at line 210 of file icl_list.c.
{
if(pos)
return pos->flink;
return NULL;
}

| icl_list_t* icl_list_prepend | ( | icl_list_t * | head, | |
| void * | data | |||
| ) |
Insert a node at the beginning of this list.
| head | -- the linked list | |
| data | -- the data to be inserted |
Definition at line 271 of file icl_list.c.
{
return(icl_list_insert(head, head, data));
}


| icl_list_t* icl_list_prev | ( | icl_list_t * | head, | |
| icl_list_t * | pos | |||
| ) |
Get the node preceding the specified node.
| head | -- the list containing the specified node | |
| pos | -- the node whose predecessor should be returned |
Definition at line 228 of file icl_list.c.
{
if(pos && pos->blink!=NULL)
return pos->blink;
return NULL;
}
| 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.
| head | -- the linked list | |
| data | -- the data to be found | |
| compare | -- function that compares the data items |
Definition at line 115 of file icl_list.c.
{
icl_list_t *node;
if (!head) return NULL;
for (node=head->flink; node!=NULL; node=node->flink) {
if(!node->data)
continue;
if((compare && (*compare)(node->data, data)==0))
break;
else if (node->data==data)
break; /* compare == NULL, then direct comparison of pointers */
}
return(node);
}

| int icl_list_size | ( | icl_list_t * | head | ) |
Get the number of items in this linked list.
| head | -- the linked list |
Definition at line 171 of file icl_list.c.
{
int size=0;
if(!head) return -1;
while((head=head->flink))
size++;
return size;
}

1.6.3-20100507