summaryrefslogtreecommitdiffstats
path: root/lib/vector.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2018-05-29 23:38:18 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2018-06-06 18:16:12 +0200
commitf428cb8a3a9cef3a1f68be6434f8db6fa9b693ef (patch)
treea9c9d4c739f9f9e8aa427e3e252c5a892513382c /lib/vector.c
parentlib: fix static analysis issues, use regfree() (diff)
downloadfrr-f428cb8a3a9cef3a1f68be6434f8db6fa9b693ef.tar.xz
frr-f428cb8a3a9cef3a1f68be6434f8db6fa9b693ef.zip
lib: add vector_compact(), use after str splits
* Add function to move all data to the start of a vector by shifting over contiguous empty slots * Use this function to remove empty slots leftover after frrstr_filter_vec Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/vector.c')
-rw-r--r--lib/vector.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/vector.c b/lib/vector.c
index 696e260cd..0631e836f 100644
--- a/lib/vector.c
+++ b/lib/vector.c
@@ -164,6 +164,16 @@ void vector_remove(vector v, unsigned int ix)
v->index[v->active] = NULL;
}
+void vector_compact(vector v)
+{
+ for (unsigned int i = 0; i < vector_active(v); ++i) {
+ if (vector_slot(v, i) == NULL) {
+ vector_remove(v, i);
+ --i;
+ }
+ }
+}
+
void vector_unset_value(vector v, void *val)
{
size_t i;