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 /* Set to 1 if plist uses a foreign obstack */
32 unsigned foreign_obstack : 1;
35 * First element in the list.
37 plist_element_t *first_element;
40 * Last element in the list.
42 plist_element_t *last_element;
45 * Current number of elements in the list.
50 * First element in the free list.
51 * Please note that the free list is a single linked list and all back
52 * references are invalid.
54 plist_element_t* first_free_element;
58 * An element in the pointer list.
60 struct _plist_element {
61 plist_element_t *next;
62 plist_element_t *prev;
67 * Creates a new pointer list and initializes it.
68 * @return The newly created pointer list.
70 plist_t *plist_new(void);
73 * Creates a new pointer list and initializes it.
74 * Uses the given obstack instead of creating one.
75 * @param obst The obstack to use
76 * @return The newly created pointer list.
78 plist_t *plist_obstack_new(struct obstack *obst);
81 * Frees the passed pointer list.
82 * After a call to this function all references to the list and any of
83 * its elements are invalid.
85 void plist_free(plist_t *list);
88 * Returns the number of elements in a pointer list.
89 * @param list the pointer list
90 * @return The number of elements in a pointer list.
92 #define plist_count(list) \
93 ((list)->element_count)
96 * Inserts an element at the back of a pointer list.
97 * @param list the pointer list to append the new element to.
98 * @param value the element value to append.
100 void plist_insert_back(plist_t *list, void *value);
103 * Inserts an element at the front of a pointer list.
104 * @param list the pointer list to prepend the new element to.
105 * @param value the element value to prepend.
107 void plist_insert_front(plist_t *list, void *value);
110 * Inserts an element into a pointer list before the specified element,
111 * which must be non null.
112 * @param list the pointer list to insert the new element into.
113 * @param element the list element before which the new element should
114 * be inserted. This element must be a part of @p list.
115 * @param value the element value to insert.
117 void plist_insert_before(plist_t *list, plist_element_t *element, void *value);
120 * Inserts an element into a pointer list after the specified element,
121 * which must be non null.
122 * @param list the pointer list to insert the new element into.
123 * @param element the list element after which the new element should
124 * be inserted. This element must be a part of @p list.
125 * @param value the element value to insert.
127 void plist_insert_after(plist_t *list, plist_element_t *element, void *value);
130 * Erases the specified element from the pointer list.
131 * @param list the pointer list from which the element should be erased.
132 * @param element the list element to erase. This element must be a part
135 void plist_erase(plist_t *list, plist_element_t *element);
138 * Erases all elements from the specified pointer list.
139 * @param list the pointer list that should be cleared.
141 void plist_clear(plist_t *list);
144 * Returns the first element of a pointer list.
145 * @param list the pointer list to iterate
146 * @return a pointer to the element or NULL if the list is empty
148 #define plist_first(list) \
149 ((list)->first_element)
152 * Returns the last element of a pointer list.
153 * @param list the pointer list to iterate
154 * @return a pointer to the element or NULL if the list is empty
156 #define plist_last(list) \
157 ((list)->last_element)
160 * Checks whether a pointer list element has a successor or not.
161 * @param element the list element that should be queried for existence
163 * @return TRUE if @p element has a successor, otherwise FALSE.
165 #define plist_element_has_next(element) \
166 ((element)->next != NULL)
169 * Checks whether a pointer list element has a predecessor or not.
170 * @param element the list element that should be queried for existence
172 * @return TRUE if @p element has a successor, otherwise FALSE.
174 #define plist_element_has_prev(element) \
175 ((element)->prev != NULL)
178 * Gets the successor of the passed list element.
179 * @param element the list element to return the successor of.
180 * @return The successor of @p element or NULL if @p element is the last
181 * element in the sequence.
183 #define plist_element_get_next(element) \
187 * Gets the predecessor of the passed list element.
188 * @param element the list element to return the predecessor of.
189 * @return The predecessor of @p element or NULL if @p element is the last
190 * element in the sequence.
192 #define plist_element_get_prev(element) \
196 * Gets the value stored in the passed list element.
197 * @param element the list element to return the value of.
198 * @return The value stored in @p element.
200 #define plist_element_get_value(element) \
204 * Convenience macro to iterate over a plist.
206 #define foreach_plist(list, el) \
207 for (el = plist_first(list); el; el = plist_element_get_next(el))