]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Implement virHashRemoveAll function
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Thu, 19 Apr 2012 14:21:43 +0000 (10:21 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Thu, 19 Apr 2012 14:21:43 +0000 (10:21 -0400)
Implement function to remove all entries of a hash table.

src/libvirt_private.syms
src/util/virhash.c
src/util/virhash.h

index 8d29e75842837690acbd6d37268cb90ac7b98207..a590a319b5685b371612228d27797172f5c6e734 100644 (file)
@@ -578,6 +578,7 @@ virHashForEach;
 virHashFree;
 virHashGetItems;
 virHashLookup;
+virHashRemoveAll;
 virHashRemoveEntry;
 virHashRemoveSet;
 virHashSearch;
index 50c6ac58352be0d7651a92046a01c7564118b317..5794d6f654d2cdb583340862a63fb2a661911574 100644 (file)
@@ -575,6 +575,31 @@ virHashRemoveSet(virHashTablePtr table,
     return count;
 }
 
+static int
+_virHashRemoveAllIter(const void *payload ATTRIBUTE_UNUSED,
+                      const void *name ATTRIBUTE_UNUSED,
+                      const void *data ATTRIBUTE_UNUSED)
+{
+    return 1;
+}
+
+/**
+ * virHashRemoveAll
+ * @table: the hash table to clear
+ *
+ * Free the hash @table's contents. The userdata is
+ * deallocated with the function provided at creation time.
+ *
+ * Returns the number of items removed on success, -1 on failure
+ */
+ssize_t
+virHashRemoveAll(virHashTablePtr table)
+{
+    return virHashRemoveSet(table,
+                            _virHashRemoveAllIter,
+                            NULL);
+}
+
 /**
  * virHashSearch:
  * @table: the hash table to search
index 7acbcbdd625dc048a1a823946b05d04183bafe6f..2c04f811f2b122f7b0a38e23ab18d21864aca42a 100644 (file)
@@ -126,6 +126,11 @@ int virHashUpdateEntry(virHashTablePtr table,
 int virHashRemoveEntry(virHashTablePtr table,
                        const void *name);
 
+/*
+ * Remove all entries from the hash table.
+ */
+ssize_t virHashRemoveAll(virHashTablePtr table);
+
 /*
  * Retrieve the userdata.
  */