From 0d9e204694fbdff2ad6c8441ba3008907ddec3db Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 25 Jan 2017 04:13:02 +0100 Subject: [PATCH] lib: add vector_unset_value() Signed-off-by: David Lamparter --- lib/vector.c | 18 ++++++++++++++++++ lib/vector.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/lib/vector.c b/lib/vector.c index 0b1d5d5046..e16fcf5315 100644 --- a/lib/vector.c +++ b/lib/vector.c @@ -165,6 +165,24 @@ vector_unset (vector v, unsigned int i) } } +void +vector_unset_value (vector v, void *val) +{ + size_t i; + + for (i = 0; i < v->active; i++) + if (v->index[i] == val) + { + v->index[i] = NULL; + break; + } + + if (i + 1 == v->active) + do + v->active--; + while (i && v->index[--i] == NULL); +} + /* Count the number of not emplty slot. */ unsigned int vector_count (vector v) diff --git a/lib/vector.h b/lib/vector.h index 28f4ad320f..f57f28bbd0 100644 --- a/lib/vector.h +++ b/lib/vector.h @@ -53,6 +53,8 @@ extern int vector_empty_slot (vector v); extern int vector_set (vector v, void *val); extern int vector_set_index (vector v, unsigned int i, void *val); extern void vector_unset (vector v, unsigned int i); +extern void vector_unset_value (vector v, void *val); + extern unsigned int vector_count (vector v); extern void vector_free (vector v); extern vector vector_copy (vector v); -- 2.39.5