]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add vector_unset_value()
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 25 Jan 2017 03:13:02 +0000 (04:13 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 31 Jan 2017 14:28:19 +0000 (15:28 +0100)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/vector.c
lib/vector.h

index 0b1d5d5046ff45d09549d7385086ec5c0107ae12..e16fcf53151437b00a96f439f588511ac9931e39 100644 (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)
index 28f4ad320ff435542032bd9f0e0843f0a9e0c084..f57f28bbd0dd71b0815c83253f80614e9588ad2a 100644 (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);