]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: hash: Add new constructor 'virHashNew'
authorPeter Krempa <pkrempa@redhat.com>
Wed, 9 Oct 2019 13:34:54 +0000 (15:34 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 21 Oct 2019 14:53:42 +0000 (16:53 +0200)
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@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
src/libvirt_private.syms
src/util/virhash.c
src/util/virhash.h

index 875ad8a7c7e451f6a6592c7a7edd7cb7849d58ee..ee8bb84041170eb9b7c6e7faec9b83b30c3f116c 100644 (file)
@@ -2071,6 +2071,7 @@ virHashForEach;
 virHashFree;
 virHashGetItems;
 virHashLookup;
+virHashNew;
 virHashRemoveAll;
 virHashRemoveEntry;
 virHashRemoveSet;
index 32de4dabad0e9567b6f80ee15976b20699fb5dce..9384d28002028b26161275abe9ef40153bf9e15f 100644 (file)
@@ -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
index 94fe8e23e4957dc01e3d36d6c7c1a32eb6e643d8..d7de0618cb80687c7a4c90babee2f7e53469ada3 100644 (file)
@@ -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,