src/llist.c: Add llist_next_filter()
This convenience function can be used to return the successor of a list item if it is matched by a filter callback and return NULL otherwise. We will use this for an improved version of the LLIST_FIND_FOREACH macro that can be used whenever results are known to be continuous. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
13
src/llist.c
13
src/llist.c
@@ -114,6 +114,19 @@ llist_next (llist_item_t *i)
|
||||
return i ? i->next : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the successor of a list item if it is matched by some filter
|
||||
* callback. Return NULL otherwise.
|
||||
*/
|
||||
llist_item_t *
|
||||
llist_next_filter (llist_item_t *i, long data, llist_fn_match_t fn_match)
|
||||
{
|
||||
if (i && i->next && fn_match (i->next->data, data))
|
||||
return i->next;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the actual data of an item.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user