#include <ctype.h>
#include <stdlib.h>
#include <string.h>
-#include "dynamic-string.h"
+#include "openvswitch/dynamic-string.h"
+#include "random.h"
#include "util.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
VLOG_DEFINE_THIS_MODULE(svec);
void
svec_sort(struct svec *svec)
{
- qsort(svec->names, svec->n, sizeof *svec->names, compare_strings);
+ if (svec->n) {
+ qsort(svec->names, svec->n, sizeof *svec->names, compare_strings);
+ }
}
void
svec->n = j;
}
+static void
+swap_strings(char **a, char **b)
+{
+ char *tmp = *a;
+ *a = *b;
+ *b = tmp;
+}
+
+void
+svec_shuffle(struct svec *svec)
+{
+ for (size_t i = 0; i < svec->n; i++) {
+ size_t j = i + random_range(svec->n - i);
+ swap_strings(&svec->names[i], &svec->names[j]);
+ }
+}
+
void
svec_diff(const struct svec *a, const struct svec *b,
struct svec *a_only, struct svec *both, struct svec *b_only)