2005-11-30 13:36:58 +00:00
|
|
|
/*
|
2006-04-09 13:11:22 +00:00
|
|
|
* Summary: Chained hash tables and domain/connections handling
|
|
|
|
* Description: This module implements the hash table and allocation and
|
|
|
|
* deallocation of domains and connections
|
2005-11-30 13:36:58 +00:00
|
|
|
*
|
2014-04-04 23:36:25 +00:00
|
|
|
* Copyright (C) 2005-2014 Red Hat, Inc.
|
2012-01-25 16:13:59 +00:00
|
|
|
* Copyright (C) 2000 Bjorn Reese and Daniel Veillard.
|
2005-11-30 13:36:58 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 16:12:59 +00:00
|
|
|
#pragma once
|
2005-11-30 13:36:58 +00:00
|
|
|
|
2015-07-02 12:21:27 +00:00
|
|
|
typedef struct _virHashAtomic virHashAtomic;
|
|
|
|
|
2005-11-30 13:36:58 +00:00
|
|
|
/*
|
|
|
|
* function types:
|
|
|
|
*/
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2006-11-15 20:11:56 +00:00
|
|
|
/**
|
|
|
|
* virHashIterator:
|
|
|
|
* @payload: the data in the hash
|
Allow hash tables to use generic pointers as keys
Relax the restriction that the hash table key must be a string
by allowing an arbitrary hash code generator + comparison func
to be provided
* util/hash.c, util/hash.h: Allow any pointer as a key
* internal.h: Include stdbool.h as standard.
* conf/domain_conf.c, conf/domain_conf.c,
conf/nwfilter_params.c, nwfilter/nwfilter_gentech_driver.c,
nwfilter/nwfilter_gentech_driver.h, nwfilter/nwfilter_learnipaddr.c,
qemu/qemu_command.c, qemu/qemu_driver.c,
qemu/qemu_process.c, uml/uml_driver.c,
xen/xm_internal.c: s/char */void */ in hash callbacks
2011-02-22 15:11:59 +00:00
|
|
|
* @name: the hash key
|
2020-10-23 09:45:16 +00:00
|
|
|
* @opaque: user supplied data blob
|
2006-11-15 20:11:56 +00:00
|
|
|
*
|
|
|
|
* Callback to process a hash entry during iteration
|
2016-02-12 09:03:50 +00:00
|
|
|
*
|
|
|
|
* Returns -1 to stop the iteration, e.g. in case of an error
|
2006-11-15 20:11:56 +00:00
|
|
|
*/
|
2020-10-23 09:45:16 +00:00
|
|
|
typedef int (*virHashIterator) (void *payload, const char *name, void *opaque);
|
2006-11-15 20:11:56 +00:00
|
|
|
/**
|
Allow hash tables to use generic pointers as keys
Relax the restriction that the hash table key must be a string
by allowing an arbitrary hash code generator + comparison func
to be provided
* util/hash.c, util/hash.h: Allow any pointer as a key
* internal.h: Include stdbool.h as standard.
* conf/domain_conf.c, conf/domain_conf.c,
conf/nwfilter_params.c, nwfilter/nwfilter_gentech_driver.c,
nwfilter/nwfilter_gentech_driver.h, nwfilter/nwfilter_learnipaddr.c,
qemu/qemu_command.c, qemu/qemu_driver.c,
qemu/qemu_process.c, uml/uml_driver.c,
xen/xm_internal.c: s/char */void */ in hash callbacks
2011-02-22 15:11:59 +00:00
|
|
|
* virHashSearcher:
|
2006-11-15 20:11:56 +00:00
|
|
|
* @payload: the data in the hash
|
Allow hash tables to use generic pointers as keys
Relax the restriction that the hash table key must be a string
by allowing an arbitrary hash code generator + comparison func
to be provided
* util/hash.c, util/hash.h: Allow any pointer as a key
* internal.h: Include stdbool.h as standard.
* conf/domain_conf.c, conf/domain_conf.c,
conf/nwfilter_params.c, nwfilter/nwfilter_gentech_driver.c,
nwfilter/nwfilter_gentech_driver.h, nwfilter/nwfilter_learnipaddr.c,
qemu/qemu_command.c, qemu/qemu_driver.c,
qemu/qemu_process.c, uml/uml_driver.c,
xen/xm_internal.c: s/char */void */ in hash callbacks
2011-02-22 15:11:59 +00:00
|
|
|
* @name: the hash key
|
2020-10-23 09:45:16 +00:00
|
|
|
* @opaque: user supplied data blob
|
2006-11-15 20:11:56 +00:00
|
|
|
*
|
|
|
|
* Callback to identify hash entry desired
|
|
|
|
* Returns 1 if the hash entry is desired, 0 to move
|
|
|
|
* to next entry
|
|
|
|
*/
|
2020-10-21 11:31:16 +00:00
|
|
|
typedef int (*virHashSearcher) (const void *payload, const char *name,
|
2020-10-23 09:45:16 +00:00
|
|
|
const void *opaque);
|
2005-11-30 13:36:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructor and destructor.
|
|
|
|
*/
|
2021-11-30 13:40:43 +00:00
|
|
|
GHashTable *virHashNew(GDestroyNotify dataFree) G_GNUC_WARN_UNUSED_RESULT;
|
|
|
|
virHashAtomic *virHashAtomicNew(GDestroyNotify dataFree);
|
2020-10-22 17:04:18 +00:00
|
|
|
ssize_t virHashSize(GHashTable *table);
|
2005-11-30 13:36:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new entry to the hash table.
|
|
|
|
*/
|
2020-10-22 17:04:18 +00:00
|
|
|
int virHashAddEntry(GHashTable *table,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name, void *userdata);
|
2020-10-22 17:04:18 +00:00
|
|
|
int virHashUpdateEntry(GHashTable *table,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name,
|
2011-02-22 15:11:59 +00:00
|
|
|
void *userdata);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virHashAtomicUpdate(virHashAtomic *table,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name,
|
2015-07-02 12:21:27 +00:00
|
|
|
void *userdata);
|
2005-11-30 13:36:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove an entry from the hash table.
|
|
|
|
*/
|
2020-10-22 17:04:18 +00:00
|
|
|
int virHashRemoveEntry(GHashTable *table,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name);
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2012-04-19 14:21:43 +00:00
|
|
|
/*
|
|
|
|
* Remove all entries from the hash table.
|
|
|
|
*/
|
2020-10-22 17:04:18 +00:00
|
|
|
void virHashRemoveAll(GHashTable *table);
|
2012-04-19 14:21:43 +00:00
|
|
|
|
2005-11-30 13:36:58 +00:00
|
|
|
/*
|
|
|
|
* Retrieve the userdata.
|
|
|
|
*/
|
2020-10-22 17:04:18 +00:00
|
|
|
void *virHashLookup(GHashTable *table, const char *name);
|
|
|
|
bool virHashHasEntry(GHashTable *table, const char *name);
|
2005-11-30 13:36:58 +00:00
|
|
|
|
2011-02-22 15:11:59 +00:00
|
|
|
/*
|
|
|
|
* Retrieve & remove the userdata.
|
|
|
|
*/
|
2020-10-22 17:04:18 +00:00
|
|
|
void *virHashSteal(GHashTable *table, const char *name);
|
2021-03-11 07:16:13 +00:00
|
|
|
void *virHashAtomicSteal(virHashAtomic *table,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name);
|
2011-02-22 15:11:59 +00:00
|
|
|
|
2011-11-18 16:58:17 +00:00
|
|
|
/*
|
|
|
|
* Get the hash table's key/value pairs and have them optionally sorted.
|
|
|
|
* The returned array contains virHashSize() elements. Additionally,
|
|
|
|
* an empty element has been added to the end of the array (with key == NULL)
|
|
|
|
* to indicate the end of the array.
|
|
|
|
* The key/value pairs are only valid as long as the underlying hash
|
|
|
|
* table is not modified, i.e., no keys are removed or inserted, and
|
|
|
|
* the hash table is not deleted.
|
|
|
|
* The caller must only free the returned array using VIR_FREE().
|
|
|
|
* The caller must make copies of all returned keys and values if they are
|
|
|
|
* to be used somewhere else.
|
|
|
|
*/
|
|
|
|
typedef struct _virHashKeyValuePair virHashKeyValuePair;
|
|
|
|
struct _virHashKeyValuePair {
|
|
|
|
const void *key;
|
|
|
|
const void *value;
|
|
|
|
};
|
2021-03-11 07:16:13 +00:00
|
|
|
virHashKeyValuePair *virHashGetItems(GHashTable *table,
|
2020-10-22 15:38:53 +00:00
|
|
|
size_t *nitems,
|
|
|
|
bool sortedKeys);
|
2006-11-15 20:11:56 +00:00
|
|
|
|
2012-01-23 20:35:54 +00:00
|
|
|
/*
|
|
|
|
* Compare two tables for equality: the lookup of a key's value in
|
|
|
|
* both tables must result in an equivalent value.
|
|
|
|
* The caller must pass in a comparator function for comparing the values
|
|
|
|
* of two keys.
|
|
|
|
*/
|
|
|
|
typedef int (*virHashValueComparator)(const void *value1, const void *value2);
|
2020-10-22 17:04:18 +00:00
|
|
|
bool virHashEqual(GHashTable *table1,
|
|
|
|
GHashTable *table2,
|
2012-01-23 20:35:54 +00:00
|
|
|
virHashValueComparator compar);
|
|
|
|
|
|
|
|
|
2006-11-15 20:11:56 +00:00
|
|
|
/*
|
|
|
|
* Iterators
|
|
|
|
*/
|
2020-10-22 17:04:18 +00:00
|
|
|
int virHashForEach(GHashTable *table, virHashIterator iter, void *opaque);
|
|
|
|
int virHashForEachSafe(GHashTable *table, virHashIterator iter, void *opaque);
|
|
|
|
int virHashForEachSorted(GHashTable *table, virHashIterator iter, void *opaque);
|
|
|
|
ssize_t virHashRemoveSet(GHashTable *table, virHashSearcher iter, const void *opaque);
|
|
|
|
void *virHashSearch(GHashTable *table, virHashSearcher iter,
|
2020-10-23 09:45:16 +00:00
|
|
|
const void *opaque, char **name);
|