summaryrefslogtreecommitdiffstats
path: root/lib/vector.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2018-05-26 00:49:53 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2018-06-06 18:16:12 +0200
commit62bece44494e5b7aefb5102bd1109e1e1376c3b3 (patch)
treee2096997453b0df42e27248de14f6de9248499ea /lib/vector.c
parent*: style for | support (diff)
downloadfrr-62bece44494e5b7aefb5102bd1109e1e1376c3b3.tar.xz
frr-62bece44494e5b7aefb5102bd1109e1e1376c3b3.zip
lib: add vector_remove() to vector.[ch]
An optimized version of this has already been implemented within graph.c that assumes some specialized constraints for that code. It's generally useful so this change implements a general purpose version of it. This fixes cmd_make_strvec() that was broken by some code shuffling in previous commits. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/vector.c')
-rw-r--r--lib/vector.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/vector.c b/lib/vector.c
index ebac2b46e..696e260cd 100644
--- a/lib/vector.c
+++ b/lib/vector.c
@@ -153,6 +153,17 @@ void vector_unset(vector v, unsigned int i)
}
}
+void vector_remove(vector v, unsigned int ix)
+{
+ if (ix >= v->active)
+ return;
+
+ int n = (--v->active) - ix;
+
+ memmove(&v->index[ix], &v->index[ix + 1], n * sizeof(void *));
+ v->index[v->active] = NULL;
+}
+
void vector_unset_value(vector v, void *val)
{
size_t i;