Skip to content

Commit 0375b67

Browse files
quariumcmassiot
authored andcommitted
ulist: add ulist_next and ulist_prev
1 parent 8e5a541 commit 0375b67

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

include/upipe/ulist.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,34 @@ static inline struct uchain *ulist_at(struct uchain *ulist, unsigned index)
214214
return NULL;
215215
}
216216

217+
/** @This return the next element in the list or NULL.
218+
*
219+
* @param ulist pointer to a ulist
220+
* @param element pointer to element
221+
* @return point to the next element or NULL
222+
*/
223+
static inline struct uchain *ulist_next(struct uchain *ulist,
224+
struct uchain *element)
225+
{
226+
if (!element)
227+
return ulist_peek(ulist);
228+
return element->next != ulist ? element->next : NULL;
229+
}
230+
231+
/** @This return the previous element in the list or NULL.
232+
*
233+
* @param ulist pointer to a ulist
234+
* @param element pointer to element
235+
* @return point to the previous element or NULL
236+
*/
237+
static inline struct uchain *ulist_prev(struct uchain *ulist,
238+
struct uchain *element)
239+
{
240+
if (!element)
241+
return ulist_peek_last(ulist);
242+
return element->prev != ulist ? element->prev : NULL;
243+
}
244+
217245
/** @This sorts through a list using a comparison function.
218246
*
219247
* @param ulist pointer to a ulist

0 commit comments

Comments
 (0)