2 * Simple, non circular, double linked pointer list.
3 * Created because the properties of the standard circular list were not
4 * very well suited for the interference graph implementation.
5 * This list uses an obstack and a free-list to efficiently manage its
7 * @author Kimon Hoffmann
10 * @note Until now the code is entirely untested so it probably contains
19 typedef struct _plist_element plist_element_t;
20 typedef struct _plist plist_t;
23 * The plist data type.
27 * The obstack used for all allocations.
31 * First element in the list.
33 plist_element_t *first_element;
35 * Last element in the list.
37 plist_element_t *last_element;
39 * Current number of elements in the list.
43 * First element in the free list.
44 * Please note that the free list is a single linked list and all back
45 * references are invalid.
47 plist_element_t* first_free_element;
51 * An element in the pointer list.
53 struct _plist_element {
54 plist_element_t* next;
55 plist_element_t* prev;
60 * Creates a new pointer list and initializes it.
61 * @return The newly created pointer list.
63 plist_t* plist_new(void);
66 * Frees the passed pointer list.
67 * After a call to this function all references to the list and any of
68 * its elements are invalid.
70 void plist_free(plist_t* list);
73 * Returns the number of elements in a pointer list.
74 * @param list the pointer list
75 * @return The number of elements in a pointer list.
77 #define plist_count(list) \
78 ((list)->element_count)
81 * Inserts an element at the back of a pointer list.
82 * @param list the pointer list to append the new element to.
83 * @param value the element value to append.
85 void plist_insert_back(plist_t* list, void* value);
88 * Inserts an element at the front of a pointer list.
89 * @param list the pointer list to prepend the new element to.
90 * @param value the element value to prepend.
92 void plist_insert_front(plist_t* list, void* value);
95 * Inserts an element into a pointer list before the specified element,
96 * which must be non null.
97 * @param list the pointer list to insert the new element into.
98 * @param element the list element before which the new element should
99 * be inserted. This element must be a part of @p list.
100 * @param value the element value to insert.
102 void plist_insert_before(plist_t* list, plist_element_t* element, void* value);
105 * Inserts an element into a pointer list after the specified element,
106 * which must be non null.
107 * @param list the pointer list to insert the new element into.
108 * @param element the list element after which the new element should
109 * be inserted. This element must be a part of @p list.
110 * @param value the element value to insert.
112 void plist_insert_after(plist_t* list, plist_element_t* element, void* value);
115 * Erases the specified element from the pointer list.
116 * @param list the pointer list from which the lement should be erased.
117 * @param element the list element to erase. This element must be a part
120 void plist_erase(plist_t* list, plist_element_t* element);
123 * Erases all elements from the specified pointer list.
124 * @param list the pointer list that should be cleard.
126 void plist_clear(plist_t* list);
129 * Returns the first element of a pointer list.
130 * @param list the pointer list to iterate
131 * @return a pointer to the element or NULL if the list is empty
133 #define plist_first(list) \
134 ((list)->first_element)
137 * Returns the last element of a pointer list.
138 * @param list the pointer list to iterate
139 * @return a pointer to the element or NULL if the list is empty
141 #define plist_last(list) \
142 ((list)->last_element)
145 * Checks whether a pointer list element has a successor or not.
146 * @param element the list element that should be queried for existance
148 * @return TRUE if @p element has a successor, otherwise FALSE.
150 #define plist_element_has_next(element) \
151 ((element)->next != NULL)
154 * Checks whether a pointer list element has a predecessor or not.
155 * @param element the list element that should be queried for existance
157 * @return TRUE if @p element has a successor, otherwise FALSE.
159 #define plist_element_has_prev(element) \
160 ((element)->prev != NULL)
163 * Gets the successor of the passed list element.
164 * @param element the list element to return the successor of.
165 * @return The successor of @p element or NULL if @p element is the last
166 * element in the sequence.
168 #define plist_element_get_next(element) \
172 * Gets the predecessor of the passed list element.
173 * @param element the list element to return the predecessor of.
174 * @return The predecessor of @p element or NULL if @p element is the last
175 * element in the sequence.
177 #define plist_element_get_prev(element) \
181 * Gets the value stored in the passed list element.
182 * @param element the list element to return the value of.
183 * @return The value stored in @p element.
185 #define plist_element_get_value(element) \
189 * Convenience macro to iterate over a plist.
191 #define foreach_plist(list, el) \
192 for (el = plist_first(list); el; el = plist_element_get_next(el))