Add a simpler constructor for hash tables which specifically does not
require specifying the initial hash size and uses simpler freeing
function.
The initial hash table size usually is not important as the hash table
is growing when it reaches certain number of entries in one bucket.
Additionally many callers pass in a random small number for ad-hoc table
use so using a central one will simplify things.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/virhash.c | 21 +++++++++++++++++++++
src/util/virhash.h | 1 +
3 files changed, 23 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0da02bb8bd..c155f51174 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2066,6 +2066,7 @@ virHashForEach;
virHashFree;
virHashGetItems;
virHashLookup;
+virHashNew;
virHashRemoveAll;
virHashRemoveEntry;
virHashRemoveSet;
diff --git a/src/util/virhash.c b/src/util/virhash.c
index 4d90fa5333..de03032bf1 100644
--- a/src/util/virhash.c
+++ b/src/util/virhash.c
@@ -169,6 +169,27 @@ virHashTablePtr virHashCreateFull(ssize_t size,
}
+/**
+ * virHashNew:
+ * @dataFree: callback to free data
+ *
+ * Create a new virHashTablePtr.
+ *
+ * Returns the newly created object, or NULL if an error occurred.
+ */
+virHashTablePtr
+virHashNew(virHashDataFreeSimple dataFree)
+{
+ return virHashCreateFull(32,
+ NULL,
+ dataFree,
+ virHashStrCode,
+ virHashStrEqual,
+ virHashStrCopy,
+ virHashStrFree);
+}
+
+
/**
* virHashCreate:
* @size: the size of the hash table
diff --git a/src/util/virhash.h b/src/util/virhash.h
index 94fe8e23e4..d7de0618cb 100644
--- a/src/util/virhash.h
+++ b/src/util/virhash.h
@@ -107,6 +107,7 @@ typedef void (*virHashKeyFree)(void *name);
/*
* Constructor and destructor.
*/
+virHashTablePtr virHashNew(virHashDataFreeSimple dataFree);
virHashTablePtr virHashCreate(ssize_t size,
virHashDataFree dataFree);
virHashAtomicPtr virHashAtomicNew(ssize_t size,
--
2.21.0