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
|
|
|
*/
|
|
|
|
|
2018-12-13 14:53:50 +00:00
|
|
|
#ifndef LIBVIRT_VIRHASH_H
|
|
|
|
# define LIBVIRT_VIRHASH_H
|
2005-11-30 13:36:58 +00:00
|
|
|
|
2012-01-26 18:14:01 +00:00
|
|
|
|
2019-04-01 13:14:30 +00:00
|
|
|
# include "virautoclean.h"
|
2018-07-24 15:52:07 +00:00
|
|
|
|
2005-11-30 13:36:58 +00:00
|
|
|
/*
|
|
|
|
* The hash table.
|
|
|
|
*/
|
2006-04-09 13:11:22 +00:00
|
|
|
typedef struct _virHashTable virHashTable;
|
|
|
|
typedef virHashTable *virHashTablePtr;
|
2005-11-30 13:36:58 +00:00
|
|
|
|
2015-07-02 12:21:27 +00:00
|
|
|
typedef struct _virHashAtomic virHashAtomic;
|
|
|
|
typedef virHashAtomic *virHashAtomicPtr;
|
|
|
|
|
2005-11-30 13:36:58 +00:00
|
|
|
/*
|
|
|
|
* function types:
|
|
|
|
*/
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2005-11-30 13:36:58 +00:00
|
|
|
/**
|
2011-02-22 15:11:59 +00:00
|
|
|
* virHashDataFree:
|
2005-11-30 13:36:58 +00:00
|
|
|
* @payload: the data in the hash
|
|
|
|
* @name: the name associated
|
|
|
|
*
|
|
|
|
* Callback to free data from a 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
|
|
|
typedef void (*virHashDataFree) (void *payload, const void *name);
|
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
|
2006-11-15 20:11:56 +00:00
|
|
|
* @data: user supplied data blob
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
2016-02-12 09:03:50 +00:00
|
|
|
typedef int (*virHashIterator) (void *payload, const void *name, void *data);
|
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
|
2006-11-15 20:11:56 +00:00
|
|
|
* @data: user supplied data blob
|
|
|
|
*
|
|
|
|
* Callback to identify hash entry desired
|
|
|
|
* Returns 1 if the hash entry is desired, 0 to move
|
|
|
|
* to next entry
|
|
|
|
*/
|
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
|
|
|
typedef int (*virHashSearcher) (const void *payload, const void *name,
|
2011-02-18 21:30:24 +00:00
|
|
|
const void *data);
|
2005-11-30 13:36:58 +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
|
|
|
/**
|
|
|
|
* virHashKeyCode:
|
|
|
|
* @name: the hash key
|
2012-01-18 16:10:43 +00:00
|
|
|
* @seed: random seed
|
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
|
|
|
*
|
2012-01-18 16:10:43 +00:00
|
|
|
* Compute the hash code corresponding to the key @name, using
|
|
|
|
* @seed to perturb the hashing algorithm
|
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
|
|
|
*
|
|
|
|
* Returns the hash code
|
|
|
|
*/
|
2012-01-18 16:10:43 +00:00
|
|
|
typedef uint32_t (*virHashKeyCode)(const void *name,
|
|
|
|
uint32_t seed);
|
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
|
|
|
/**
|
|
|
|
* virHashKeyEqual:
|
|
|
|
* @namea: the first hash key
|
|
|
|
* @nameb: the second hash key
|
|
|
|
*
|
|
|
|
* Compare two hash keys for equality
|
|
|
|
*
|
|
|
|
* Returns true if the keys are equal, false otherwise
|
|
|
|
*/
|
|
|
|
typedef bool (*virHashKeyEqual)(const void *namea, const void *nameb);
|
|
|
|
/**
|
|
|
|
* virHashKeyCopy:
|
|
|
|
* @name: the hash key
|
|
|
|
*
|
|
|
|
* Create a copy of the hash key, duplicating
|
|
|
|
* memory allocation where applicable
|
|
|
|
*
|
|
|
|
* Returns a newly allocated copy of @name
|
|
|
|
*/
|
|
|
|
typedef void *(*virHashKeyCopy)(const void *name);
|
|
|
|
/**
|
|
|
|
* virHashKeyFree:
|
|
|
|
* @name: the hash key
|
|
|
|
*
|
|
|
|
* Free any memory associated with the hash
|
|
|
|
* key @name
|
|
|
|
*/
|
|
|
|
typedef void (*virHashKeyFree)(void *name);
|
|
|
|
|
2005-11-30 13:36:58 +00:00
|
|
|
/*
|
|
|
|
* Constructor and destructor.
|
|
|
|
*/
|
2012-01-25 15:55:00 +00:00
|
|
|
virHashTablePtr virHashCreate(ssize_t size,
|
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
|
|
|
virHashDataFree dataFree);
|
2015-07-02 12:21:27 +00:00
|
|
|
virHashAtomicPtr virHashAtomicNew(ssize_t size,
|
|
|
|
virHashDataFree dataFree);
|
2012-01-25 15:55:00 +00:00
|
|
|
virHashTablePtr virHashCreateFull(ssize_t size,
|
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
|
|
|
virHashDataFree dataFree,
|
|
|
|
virHashKeyCode keyCode,
|
|
|
|
virHashKeyEqual keyEqual,
|
|
|
|
virHashKeyCopy keyCopy,
|
|
|
|
virHashKeyFree keyFree);
|
2011-02-18 21:30:24 +00:00
|
|
|
void virHashFree(virHashTablePtr table);
|
maint: avoid 'const fooPtr' in hashes
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up virhash to provide a const-correct interface: all actions
that don't modify the table take a const table. Note that in
one case (virHashSearch), we actually strip const away - we aren't
modifying the contents of the table, so much as associated data
for ensuring that the code uses the table correctly (if this were
C++, it would be a case for the 'mutable' keyword).
* src/util/virhash.h (virHashKeyComparator, virHashEqual): Use
intended type.
(virHashSize, virHashTableSize, virHashLookup, virHashSearch):
Make const-correct.
* src/util/virhash.c (virHashEqualData, virHashEqual)
(virHashLookup, virHashSize, virHashTableSize, virHashSearch)
(virHashComputeKey): Fix fallout.
* src/conf/nwfilter_params.c
(virNWFilterFormatParameterNameSorter): Likewise.
* src/nwfilter/nwfilter_ebiptables_driver.c
(ebiptablesFilterOrderSort): Likewise.
* tests/virhashtest.c (testHashGetItemsCompKey)
(testHashGetItemsCompValue): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 02:30:35 +00:00
|
|
|
ssize_t virHashSize(const virHashTable *table);
|
|
|
|
ssize_t virHashTableSize(const virHashTable *table);
|
2005-11-30 13:36:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new entry to the hash table.
|
|
|
|
*/
|
2006-04-09 13:11:22 +00:00
|
|
|
int virHashAddEntry(virHashTablePtr table,
|
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
|
|
|
const void *name, void *userdata);
|
2006-04-09 13:11:22 +00:00
|
|
|
int virHashUpdateEntry(virHashTablePtr table,
|
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
|
|
|
const void *name,
|
2011-02-22 15:11:59 +00:00
|
|
|
void *userdata);
|
2015-07-02 12:21:27 +00:00
|
|
|
int virHashAtomicUpdate(virHashAtomicPtr table,
|
|
|
|
const void *name,
|
|
|
|
void *userdata);
|
2005-11-30 13:36:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove an entry from the hash table.
|
|
|
|
*/
|
2006-04-09 13:11:22 +00:00
|
|
|
int virHashRemoveEntry(virHashTablePtr table,
|
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
|
|
|
const void *name);
|
2006-03-15 12:13:25 +00:00
|
|
|
|
2012-04-19 14:21:43 +00:00
|
|
|
/*
|
|
|
|
* Remove all entries from the hash table.
|
|
|
|
*/
|
|
|
|
ssize_t virHashRemoveAll(virHashTablePtr table);
|
|
|
|
|
2005-11-30 13:36:58 +00:00
|
|
|
/*
|
|
|
|
* Retrieve the userdata.
|
|
|
|
*/
|
maint: avoid 'const fooPtr' in hashes
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up virhash to provide a const-correct interface: all actions
that don't modify the table take a const table. Note that in
one case (virHashSearch), we actually strip const away - we aren't
modifying the contents of the table, so much as associated data
for ensuring that the code uses the table correctly (if this were
C++, it would be a case for the 'mutable' keyword).
* src/util/virhash.h (virHashKeyComparator, virHashEqual): Use
intended type.
(virHashSize, virHashTableSize, virHashLookup, virHashSearch):
Make const-correct.
* src/util/virhash.c (virHashEqualData, virHashEqual)
(virHashLookup, virHashSize, virHashTableSize, virHashSearch)
(virHashComputeKey): Fix fallout.
* src/conf/nwfilter_params.c
(virNWFilterFormatParameterNameSorter): Likewise.
* src/nwfilter/nwfilter_ebiptables_driver.c
(ebiptablesFilterOrderSort): Likewise.
* tests/virhashtest.c (testHashGetItemsCompKey)
(testHashGetItemsCompValue): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 02:30:35 +00:00
|
|
|
void *virHashLookup(const virHashTable *table, const void *name);
|
2005-11-30 13:36:58 +00:00
|
|
|
|
2011-02-22 15:11:59 +00:00
|
|
|
/*
|
|
|
|
* Retrieve & remove the userdata.
|
|
|
|
*/
|
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
|
|
|
void *virHashSteal(virHashTablePtr table, const void *name);
|
2015-07-02 12:21:27 +00:00
|
|
|
void *virHashAtomicSteal(virHashAtomicPtr table,
|
|
|
|
const void *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;
|
|
|
|
typedef virHashKeyValuePair *virHashKeyValuePairPtr;
|
|
|
|
struct _virHashKeyValuePair {
|
|
|
|
const void *key;
|
|
|
|
const void *value;
|
|
|
|
};
|
maint: avoid 'const fooPtr' in hashes
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up virhash to provide a const-correct interface: all actions
that don't modify the table take a const table. Note that in
one case (virHashSearch), we actually strip const away - we aren't
modifying the contents of the table, so much as associated data
for ensuring that the code uses the table correctly (if this were
C++, it would be a case for the 'mutable' keyword).
* src/util/virhash.h (virHashKeyComparator, virHashEqual): Use
intended type.
(virHashSize, virHashTableSize, virHashLookup, virHashSearch):
Make const-correct.
* src/util/virhash.c (virHashEqualData, virHashEqual)
(virHashLookup, virHashSize, virHashTableSize, virHashSearch)
(virHashComputeKey): Fix fallout.
* src/conf/nwfilter_params.c
(virNWFilterFormatParameterNameSorter): Likewise.
* src/nwfilter/nwfilter_ebiptables_driver.c
(ebiptablesFilterOrderSort): Likewise.
* tests/virhashtest.c (testHashGetItemsCompKey)
(testHashGetItemsCompValue): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 02:30:35 +00:00
|
|
|
typedef int (*virHashKeyComparator)(const virHashKeyValuePair *,
|
|
|
|
const virHashKeyValuePair *);
|
2011-11-18 16:58:17 +00:00
|
|
|
virHashKeyValuePairPtr virHashGetItems(virHashTablePtr table,
|
|
|
|
virHashKeyComparator compar);
|
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);
|
maint: avoid 'const fooPtr' in hashes
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up virhash to provide a const-correct interface: all actions
that don't modify the table take a const table. Note that in
one case (virHashSearch), we actually strip const away - we aren't
modifying the contents of the table, so much as associated data
for ensuring that the code uses the table correctly (if this were
C++, it would be a case for the 'mutable' keyword).
* src/util/virhash.h (virHashKeyComparator, virHashEqual): Use
intended type.
(virHashSize, virHashTableSize, virHashLookup, virHashSearch):
Make const-correct.
* src/util/virhash.c (virHashEqualData, virHashEqual)
(virHashLookup, virHashSize, virHashTableSize, virHashSearch)
(virHashComputeKey): Fix fallout.
* src/conf/nwfilter_params.c
(virNWFilterFormatParameterNameSorter): Likewise.
* src/nwfilter/nwfilter_ebiptables_driver.c
(ebiptablesFilterOrderSort): Likewise.
* tests/virhashtest.c (testHashGetItemsCompKey)
(testHashGetItemsCompValue): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 02:30:35 +00:00
|
|
|
bool virHashEqual(const virHashTable *table1,
|
|
|
|
const virHashTable *table2,
|
2012-01-23 20:35:54 +00:00
|
|
|
virHashValueComparator compar);
|
|
|
|
|
|
|
|
|
2006-11-15 20:11:56 +00:00
|
|
|
/*
|
|
|
|
* Iterators
|
|
|
|
*/
|
2016-02-12 09:15:57 +00:00
|
|
|
int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data);
|
2012-01-25 15:55:00 +00:00
|
|
|
ssize_t virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, const void *data);
|
maint: avoid 'const fooPtr' in hashes
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up virhash to provide a const-correct interface: all actions
that don't modify the table take a const table. Note that in
one case (virHashSearch), we actually strip const away - we aren't
modifying the contents of the table, so much as associated data
for ensuring that the code uses the table correctly (if this were
C++, it would be a case for the 'mutable' keyword).
* src/util/virhash.h (virHashKeyComparator, virHashEqual): Use
intended type.
(virHashSize, virHashTableSize, virHashLookup, virHashSearch):
Make const-correct.
* src/util/virhash.c (virHashEqualData, virHashEqual)
(virHashLookup, virHashSize, virHashTableSize, virHashSearch)
(virHashComputeKey): Fix fallout.
* src/conf/nwfilter_params.c
(virNWFilterFormatParameterNameSorter): Likewise.
* src/nwfilter/nwfilter_ebiptables_driver.c
(ebiptablesFilterOrderSort): Likewise.
* tests/virhashtest.c (testHashGetItemsCompKey)
(testHashGetItemsCompValue): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 02:30:35 +00:00
|
|
|
void *virHashSearch(const virHashTable *table, virHashSearcher iter,
|
2017-06-13 13:56:14 +00:00
|
|
|
const void *data, void **name);
|
2006-11-15 20:11:56 +00:00
|
|
|
|
2014-04-04 23:36:25 +00:00
|
|
|
/* Convenience for when VIR_FREE(value) is sufficient as a data freer. */
|
|
|
|
void virHashValueFree(void *value, const void *name);
|
|
|
|
|
2019-02-07 17:18:52 +00:00
|
|
|
VIR_DEFINE_AUTOPTR_FUNC(virHashTable, virHashFree);
|
2018-07-24 15:52:07 +00:00
|
|
|
|
2018-12-13 14:53:50 +00:00
|
|
|
#endif /* LIBVIRT_VIRHASH_H */
|