lib: add vector_unset_value()

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2017-01-25 04:13:02 +01:00
parent 66d29a54a1
commit 0d9e204694
2 changed files with 20 additions and 0 deletions

View file

@ -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)

View file

@ -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);