Commit ee2d838b authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼

list: added vlist_filter() to remove elements which dont match a condition

parent d9ab86c9
......@@ -133,6 +133,9 @@ ssize_t vlist_index(struct vlist *l, void *value);
/** Extend the list to the given length by filling new slots with given value. */
void vlist_extend(struct vlist *l, size_t len, void *val);
/** Remove all elements for which the callback returns a non-zero return code. */
void vlist_filter(struct vlist *l, dtor_cb_t cb);
#ifdef __cplusplus
......@@ -299,3 +299,20 @@ void vlist_extend(struct vlist *l, size_t len, void *val)
while (vlist_length(l) < len)
vlist_push(l, val);
void vlist_filter(struct vlist *l, dtor_cb_t cb)
size_t u, j;
for (i = 0, j = 0; i < vlist_length(l); i++) {
void *e = vlist_at(l, i);
if (!cb(e))
l->array[j++] = e;
l->length = j;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment