mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
util: hash: Introduce virHashHasEntry
Add a helper that checks whether an entry with given name exists but does not touch the userdata. Signed-off-by: Peter Krempa <pkrempa@redhat.com> ACKed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
defd31358e
commit
36d934e7ae
@ -2070,6 +2070,7 @@ virHashEqual;
|
||||
virHashForEach;
|
||||
virHashFree;
|
||||
virHashGetItems;
|
||||
virHashHasEntry;
|
||||
virHashLookup;
|
||||
virHashNew;
|
||||
virHashRemoveAll;
|
||||
|
@ -445,6 +445,26 @@ virHashAtomicUpdate(virHashAtomicPtr table,
|
||||
}
|
||||
|
||||
|
||||
static virHashEntryPtr
|
||||
virHashGetEntry(const virHashTable *table,
|
||||
const void *name)
|
||||
{
|
||||
size_t key;
|
||||
virHashEntryPtr entry;
|
||||
|
||||
if (!table || !name)
|
||||
return NULL;
|
||||
|
||||
key = virHashComputeKey(table, name);
|
||||
for (entry = table->table[key]; entry; entry = entry->next) {
|
||||
if (table->keyEqual(entry->name, name))
|
||||
return entry;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virHashLookup:
|
||||
* @table: the hash table
|
||||
@ -457,18 +477,29 @@ virHashAtomicUpdate(virHashAtomicPtr table,
|
||||
void *
|
||||
virHashLookup(const virHashTable *table, const void *name)
|
||||
{
|
||||
size_t key;
|
||||
virHashEntryPtr entry;
|
||||
virHashEntryPtr entry = virHashGetEntry(table, name);
|
||||
|
||||
if (!table || !name)
|
||||
if (!entry)
|
||||
return NULL;
|
||||
|
||||
key = virHashComputeKey(table, name);
|
||||
for (entry = table->table[key]; entry; entry = entry->next) {
|
||||
if (table->keyEqual(entry->name, name))
|
||||
return entry->payload;
|
||||
}
|
||||
return NULL;
|
||||
return entry->payload;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virHashHasEntry:
|
||||
* @table: the hash table
|
||||
* @name: the name of the userdata
|
||||
*
|
||||
* Find whether entry specified by @name exists.
|
||||
*
|
||||
* Returns true if the entry exists and false otherwise
|
||||
*/
|
||||
bool
|
||||
virHashHasEntry(const virHashTable *table,
|
||||
const void *name)
|
||||
{
|
||||
return !!virHashGetEntry(table, name);
|
||||
}
|
||||
|
||||
|
||||
|
@ -150,6 +150,7 @@ ssize_t virHashRemoveAll(virHashTablePtr table);
|
||||
* Retrieve the userdata.
|
||||
*/
|
||||
void *virHashLookup(const virHashTable *table, const void *name);
|
||||
bool virHashHasEntry(const virHashTable *table, const void *name);
|
||||
|
||||
/*
|
||||
* Retrieve & remove the userdata.
|
||||
|
Loading…
Reference in New Issue
Block a user