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
|
|
|
*
|
2012-01-25 16:13:59 +00:00
|
|
|
* Copyright (C) 2005-2012 Red Hat, Inc.
|
|
|
|
* Copyright (C) 2000 Bjorn Reese and Daniel Veillard.
|
2005-11-30 13:36:58 +00:00
|
|
|
*
|
|
|
|
* Author: Bjorn Reese <bjorn.reese@systematic.dk>
|
2006-04-09 13:11:22 +00:00
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
2005-11-30 13:36:58 +00:00
|
|
|
*/
|
|
|
|
|
2005-12-05 11:16:07 +00:00
|
|
|
#ifndef __VIR_HASH_H__
|
2010-03-09 18:22:22 +00:00
|
|
|
# define __VIR_HASH_H__
|
2005-11-30 13:36:58 +00:00
|
|
|
|
2012-01-26 18:14:01 +00:00
|
|
|
# include <stdint.h>
|
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
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 (*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);
|
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);
|
2012-01-25 15:55:00 +00:00
|
|
|
ssize_t virHashSize(virHashTablePtr table);
|
|
|
|
ssize_t virHashTableSize(virHashTablePtr 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);
|
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.
|
|
|
|
*/
|
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 *virHashLookup(virHashTablePtr 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);
|
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;
|
|
|
|
};
|
|
|
|
typedef int (*virHashKeyComparator)(const virHashKeyValuePairPtr,
|
|
|
|
const virHashKeyValuePairPtr);
|
|
|
|
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);
|
|
|
|
bool virHashEqual(const virHashTablePtr table1,
|
|
|
|
const virHashTablePtr table2,
|
|
|
|
virHashValueComparator compar);
|
|
|
|
|
|
|
|
|
2006-11-15 20:11:56 +00:00
|
|
|
/*
|
|
|
|
* Iterators
|
|
|
|
*/
|
2012-01-25 15:55:00 +00:00
|
|
|
ssize_t virHashForEach(virHashTablePtr table, virHashIterator iter, void *data);
|
|
|
|
ssize_t virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, const void *data);
|
2006-11-15 20:11:56 +00:00
|
|
|
void *virHashSearch(virHashTablePtr table, virHashSearcher iter, const void *data);
|
|
|
|
|
2006-03-15 12:13:25 +00:00
|
|
|
#endif /* ! __VIR_HASH_H__ */
|