[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH V10 1/7] Implement virHashRemoveAll function



Implement function to remove all entries of a hash table.

---
 src/libvirt_private.syms |    1 +
 src/util/virhash.c       |   25 +++++++++++++++++++++++++
 src/util/virhash.h       |    5 +++++
 3 files changed, 31 insertions(+)

Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -578,6 +578,7 @@ virHashForEach;
 virHashFree;
 virHashGetItems;
 virHashLookup;
+virHashRemoveAll;
 virHashRemoveEntry;
 virHashRemoveSet;
 virHashSearch;
Index: libvirt-acl/src/util/virhash.c
===================================================================
--- libvirt-acl.orig/src/util/virhash.c
+++ libvirt-acl/src/util/virhash.c
@@ -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: libvirt-acl/src/util/virhash.h
===================================================================
--- libvirt-acl.orig/src/util/virhash.h
+++ libvirt-acl/src/util/virhash.h
@@ -127,6 +127,11 @@ int virHashRemoveEntry(virHashTablePtr t
                        const void *name);
 
 /*
+ * Remove all entries from the hash table.
+ */
+ssize_t virHashRemoveAll(virHashTablePtr table);
+
+/*
  * Retrieve the userdata.
  */
 void *virHashLookup(virHashTablePtr table, const void *name);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]