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, 2011 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
#ifndef __VIR_HASH_H__
13
# 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
/**
 * 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
 */
52 53
typedef int (*virHashSearcher) (const void *payload, const char *name,
                                const void *data);
D
Daniel Veillard 已提交
54 55 56 57

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

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

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

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

82 83 84 85

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

90
#endif                          /* ! __VIR_HASH_H__ */