Implementation of a virIntSet class.

---
 src/Makefile.am          |    1 
 src/libvirt_private.syms |    8 +++++
 src/util/virintset.c     |   74 +++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virintset.h     |   44 +++++++++++++++++++++++++++
 4 files changed, 127 insertions(+)

Index: libvirt/src/Makefile.am
===================================================================
--- libvirt.orig/src/Makefile.am
+++ libvirt/src/Makefile.am
@@ -75,6 +75,7 @@ UTIL_SOURCES =							\
 		util/virhashcode.c util/virhashcode.h		\
 		util/virhook.c util/virhook.h			\
 		util/virinitctl.c util/virinitctl.h		\
+		util/virintset.c util/virintset.h		\
 		util/viriptables.c util/viriptables.h		\
 		util/virjson.c util/virjson.h			\
 		util/virkeycode.c util/virkeycode.h		\
Index: libvirt/src/util/virintset.c
===================================================================
--- /dev/null
+++ libvirt/src/util/virintset.c
@@ -0,0 +1,74 @@
+/*
+ * virintset.c: integer set
+ *
+ * Copyright (C) 2013 IBM Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *     Stefan Berger <stefanb@linux.vnet.ibm.com>
+ */
+#include "virintset.h"
+#include "viralloc.h"
+
+void virIntSetInit(virIntSetPtr set)
+{
+    set->size = 0;
+    set->capacity = 0;
+    set->set = NULL;
+}
+
+void virIntSetClear(virIntSetPtr set)
+{
+    VIR_FREE(set->set);
+    virIntSetInit(set);
+}
+
+ssize_t virIntSetAdd(virIntSetPtr set, int val)
+{
+    size_t res;
+
+    if (virIntSetIndexOf(set, val) > 0)
+        return -EEXIST;
+
+    if (set->capacity <= set->size) {
+        if (VIR_REALLOC_N(set->set, set->capacity + 10) < 0) {
+            return -ENOMEM;
+        }
+        set->capacity += 10;
+    }
+
+    res = set->size;
+
+    set->set[set->size++] = val;
+
+    return res;
+}
+
+size_t virIntSetSize(const virIntSetPtr set)
+{
+    return set->size;
+}
+
+ssize_t virIntSetIndexOf(const virIntSetPtr set, int val)
+{
+    size_t i;
+
+    for (i = 0; i < set->size; i++)
+        if (set->set[i] == val)
+            return i;
+
+    return -ENOENT;
+}
Index: libvirt/src/util/virintset.h
===================================================================
--- /dev/null
+++ libvirt/src/util/virintset.h
@@ -0,0 +1,44 @@
+/*
+ * virintset.h: integer set
+ *
+ * Copyright (C) 2013 IBM Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *     Stefan Berger <stefanb@linux.vnet.ibm.com>
+ */
+
+#ifndef __VIR_INTSET_H__
+# define __VIR_INTSET_H__
+
+# include "internal.h"
+
+typedef struct _virIntSet virIntSet;
+typedef virIntSet *virIntSetPtr;
+
+struct _virIntSet {
+    size_t size;
+    size_t capacity;
+    int *set;
+};
+
+void virIntSetInit(virIntSetPtr set);
+void virIntSetClear(virIntSetPtr set);
+ssize_t virIntSetAdd(virIntSetPtr set, int val);
+size_t virIntSetSize(const virIntSetPtr set);
+ssize_t virIntSetIndexOf(const virIntSetPtr set, int val);
+
+#endif /* __VIR_INTSET_H__ */
Index: libvirt/src/libvirt_private.syms
===================================================================
--- libvirt.orig/src/libvirt_private.syms
+++ libvirt/src/libvirt_private.syms
@@ -1393,6 +1393,14 @@ virFileWrapperFdNew;
 virInitctlSetRunLevel;
 
 
+# virintset.h
+virIntSetAdd;
+virIntSetClear;
+virIntSetIndexOf;
+virIntSetInit;
+virIntSetSize;
+
+
 # virkeycode.h
 virKeycodeSetTypeFromString;
 virKeycodeSetTypeToString;


