hash.h 2.4 KB
Newer Older
D
Daniel Veillard 已提交
1
/*
2 3 4
 * Summary: Chained hash tables and domain/connections handling
 * Description: This module implements the hash table and allocation and
 *              deallocation of domains and connections
D
Daniel Veillard 已提交
5
 *
6
 * Copy: Copyright (C) 2005 Red Hat, Inc.
D
Daniel Veillard 已提交
7 8
 *
 * Author: Bjorn Reese <bjorn.reese@systematic.dk>
9
 *         Daniel Veillard <veillard@redhat.com>
D
Daniel Veillard 已提交
10 11
 */

12 13
#ifndef __VIR_HASH_H__
#define __VIR_HASH_H__
D
Daniel Veillard 已提交
14 15 16 17

/*
 * The hash table.
 */
18 19
typedef struct _virHashTable virHashTable;
typedef virHashTable *virHashTablePtr;
D
Daniel Veillard 已提交
20 21 22 23

/*
 * function types:
 */
24

D
Daniel Veillard 已提交
25
/**
26
 * virHashDeallocator:
D
Daniel Veillard 已提交
27 28 29 30 31
 * @payload:  the data in the hash
 * @name:  the name associated
 *
 * Callback to free data from a hash.
 */
32 33 34 35 36 37 38 39 40
typedef void (*virHashDeallocator) (void *payload, const char *name);
/**
 * virHashIterator:
 * @payload: the data in the hash
 * @name: the name associated
 * @data: user supplied data blob
 *
 * Callback to process a hash entry during iteration
 */
41
typedef void (*virHashIterator) (void *payload, const char *name, void *data);
42 43 44 45 46 47 48 49 50 51 52
/**
 * virHashSearcher
 * @payload: the data in the hash
 * @name: the name associated
 * @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
 */
typedef int (*virHashSearcher) (const void *payload, const char *name, const void *data);
D
Daniel Veillard 已提交
53 54 55 56

/*
 * Constructor and destructor.
 */
57 58 59
virHashTablePtr virHashCreate(int size);
void virHashFree(virHashTablePtr table, virHashDeallocator f);
int virHashSize(virHashTablePtr table);
D
Daniel Veillard 已提交
60 61 62 63

/*
 * Add a new entry to the hash table.
 */
64
int virHashAddEntry(virHashTablePtr table,
65
                    const char *name, void *userdata);
66
int virHashUpdateEntry(virHashTablePtr table,
67 68
                       const char *name,
                       void *userdata, virHashDeallocator f);
D
Daniel Veillard 已提交
69 70 71 72

/*
 * Remove an entry from the hash table.
 */
73
int virHashRemoveEntry(virHashTablePtr table,
74
                       const char *name, virHashDeallocator f);
75

D
Daniel Veillard 已提交
76 77 78
/*
 * Retrieve the userdata.
 */
79
void *virHashLookup(virHashTablePtr table, const char *name);
D
Daniel Veillard 已提交
80

81 82 83 84

/*
 * Iterators
 */
85
int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data);
86 87 88
int virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, virHashDeallocator f, const void *data);
void *virHashSearch(virHashTablePtr table, virHashSearcher iter, const void *data);

89
#endif                          /* ! __VIR_HASH_H__ */