mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: hash: Add new constructor 'virHashNew'
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>
This commit is contained in:
parent
49288fac96
commit
defd31358e
@ -2071,6 +2071,7 @@ virHashForEach;
|
||||
virHashFree;
|
||||
virHashGetItems;
|
||||
virHashLookup;
|
||||
virHashNew;
|
||||
virHashRemoveAll;
|
||||
virHashRemoveEntry;
|
||||
virHashRemoveSet;
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user