src/cx/linked_list.h

changeset 475
31bf97fdbf71
parent 473
1bd4b8c28722
child 476
60ff4561dc04
equal deleted inserted replaced
474:9c1fccda16bc 475:31bf97fdbf71
95 * @return the node found at the specified index 95 * @return the node found at the specified index
96 */ 96 */
97 void *cx_linked_list_at(void *start, size_t start_index, ptrdiff_t loc_advance, size_t index); 97 void *cx_linked_list_at(void *start, size_t start_index, ptrdiff_t loc_advance, size_t index);
98 98
99 /** 99 /**
100 * Finds the first node in a linked list.
101 *
102 * The function starts with the pointer denoted by \p node and traverses the list
103 * along a prev pointer whose location within the node struct is
104 * denoted by \p loc_prev.
105 *
106 * @param node a pointer to a node in the list
107 * @param loc_prev the location of the \c prev pointer
108 * @return a pointer to the first node or \c NULL if \p node is \c NULL
109 */
110 void *cx_linked_list_first(void *node, ptrdiff_t loc_prev);
111
112 /**
100 * Finds the last node in a linked list. 113 * Finds the last node in a linked list.
101 * 114 *
102 * The function starts with the pointer denoted by \p begin and traverses the list 115 * The function starts with the pointer denoted by \p node and traverses the list
103 * along a next pointer whose location within the node struct is 116 * along a next pointer whose location within the node struct is
104 * denoted by \p loc_next. 117 * denoted by \p loc_next.
105 * 118 *
106 * @param begin a pointer to the begin node 119 * @param node a pointer to a node in the list
107 * @param loc_next the location of the \c next pointer 120 * @param loc_next the location of the \c next pointer
108 * @return a pointer to the last node or \c NULL if \p begin is \c NULL 121 * @return a pointer to the last node or \c NULL if \p begin is \c NULL
109 */ 122 */
110 void *cx_linked_list_last(void *begin, ptrdiff_t loc_next); 123 void *cx_linked_list_last(void *node, ptrdiff_t loc_next);
111 124
112 /** 125 /**
113 * Finds the predecessor of a node in case it is not linked. 126 * Finds the predecessor of a node in case it is not linked.
114 * 127 *
115 * \remark If \p node is not contained in the list starting with \p begin, the behavior is undefined. 128 * \remark If \p node is not contained in the list starting with \p begin, the behavior is undefined.
121 */ 134 */
122 void *cx_linked_list_prev(void *begin, ptrdiff_t loc_next, void *node); 135 void *cx_linked_list_prev(void *begin, ptrdiff_t loc_next, void *node);
123 136
124 /** 137 /**
125 * Adds a new node to a linked list. 138 * Adds a new node to a linked list.
139 * The node must not be part of any list already.
126 * 140 *
127 * \remark One of the pointers \p begin and \p end may be \c NULL, but not both. 141 * \remark One of the pointers \p begin and \p end may be \c NULL, but not both.
128 * 142 *
129 * @param begin a pointer to the begin node pointer (if your list has one) 143 * @param begin a pointer to the begin node pointer (if your list has one)
130 * @param end a pointer to the end node pointer (if your list has one) 144 * @param end a pointer to the end node pointer (if your list has one)
131 * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) 145 * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one)
132 * @param loc_next the location of a \c next pointer within your node struct (required) 146 * @param loc_next the location of a \c next pointer within your node struct (required)
133 * @param new_node a pointer to the node that shall be appended 147 * @param new_node a pointer to the node that shall be appended
134 */ 148 */
135 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); 149 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node);
150
151 /**
152 * Prepends a new node to a linked list.
153 * The node must not be part of any list already.
154 *
155 * \remark One of the pointers \p begin and \p end may be \c NULL, but not both.
156 *
157 * @param begin a pointer to the begin node pointer (if your list has one)
158 * @param end a pointer to the end node pointer (if your list has one)
159 * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one)
160 * @param loc_next the location of a \c next pointer within your node struct (required)
161 * @param new_node a pointer to the node that shall be prepended
162 */
163 void cx_linked_list_prepend(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node);
136 164
137 /** 165 /**
138 * Removes a node from the linked list. 166 * Removes a node from the linked list.
139 * 167 *
140 * If the node to remove is the begin (resp. end) node of the list and if \p begin (resp. \p end) 168 * If the node to remove is the begin (resp. end) node of the list and if \p begin (resp. \p end)

mercurial