1
#ifndef __H_LINKED_LIST__
2
#define __H_LINKED_LIST__
8
* This file, as the rest of the project is under MIT license.
9
* see http://opensource.org/licenses/MIT
11
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
15
* A LinkedList represents a linked list. A linked list is an efficient data
16
* structure. It is not posible to index a linked list.
20
* Represents an object in a LinkedList.
22
typedef struct LinkedListNode {
23
LinkedListNode * prev;
24
LinkedListNode * next;
29
* A linked list is a data stucture that holds information in a non-idexible
30
* way. It is good when the objects in the list in verry mutable, but has a
33
typedef struct LinkedList {
34
size_t len; /**< The length of the list, may be wrong.*/
35
void (* free_func)(void *); /**< The function that frees the data. */
36
LinkedListNode * head; /**< head->prev must be NULL */
37
LinkedListNode * tail; /**< tail->next must be NULL */
38
LinkedListNode * current; /**< Represents the curret object*/
42
* Create a new linked list.
44
* @param free_func the function to be used when freeing a linked list,
45
* if it is NULL the free func will be set to the standard free() function.
47
LinkedList * linked_list_new (void (* free_func)(void *));
50
* frees a linked list.
52
* @param self the linked list to free.
53
* @param free_data default:true, wether or not to free the data in the list
54
* as well as the list.
56
void linked_list_free (LinkedList * self, bool free_data = true);
59
* Add an item to a linked list.
61
* @param self the list to add an itme to.
62
* @param data the data to be stored.
64
void linked_list_add (LinkedList * self, void * data);
67
* Iterate to the next item. This function does not return anything.
69
* @param self the list to iterate over.
71
void linked_list_next (LinkedList * self);
74
* Iterate to the provious item. This function does not return anything.
76
* @param self the list to iterate over.
78
void linked_list_pev (LinkedList * self);
81
* Get the current item.
83
void * linked_list_get_current (LinkedList * self);
88
void * linked_list_get_next (LinkedList * self);
93
void * linked_list_get_prev (LinkedList * self);
96
* Wind the list to the head (start).
98
void linked_list_head (LinkedList * self);
101
* Wind the the list to the tail (end).
103
void linked_list_tail (LinkedList * self);
106
* Get the length of the list.
108
* @warning the value may be wrong.
110
size_t linked_list_len (LinkedList * self);
112
#endif /* __H_LINKED_LIST__ */