[PATCH V9 1/6] Implement virHashRemoveAll function

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

 



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);

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]