ia64/xen-unstable

view tools/vtpm_manager/util/hashtable_itr.h @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 3233e7ecfa9f
children 06d84bf87159
line source
1 /*
2 * Copyright (c) 2005, Intel Corp
3 * Copyright (c) 2002, Christopher Clark <firstname.lastname@cl.cam.ac.uk>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * * Neither the name of the original author; nor the names of any contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
36 #ifndef __HASHTABLE_ITR_CWC22__
37 #define __HASHTABLE_ITR_CWC22__
38 #include "hashtable.h"
39 #include "hashtable_private.h" /* needed to enable inlining */
41 /*****************************************************************************/
42 /* This struct is only concrete here to allow the inlining of two of the
43 * accessor functions. */
44 struct hashtable_itr
45 {
46 struct hashtable *h;
47 struct entry *e;
48 struct entry *parent;
49 unsigned int index;
50 };
53 /*****************************************************************************/
54 /* hashtable_iterator
55 */
57 struct hashtable_itr *
58 hashtable_iterator(struct hashtable *h);
60 /*****************************************************************************/
61 /* hashtable_iterator_key
62 * - return the value of the (key,value) pair at the current position */
64 void *hashtable_iterator_key(struct hashtable_itr *i);
66 /*****************************************************************************/
67 /* value - return the value of the (key,value) pair at the current position */
69 void *hashtable_iterator_value(struct hashtable_itr *i);
71 /*****************************************************************************/
72 /* advance - advance the iterator to the next element
73 * returns zero if advanced to end of table */
75 int
76 hashtable_iterator_advance(struct hashtable_itr *itr);
78 /*****************************************************************************/
79 /* remove - remove current element and advance the iterator to the next element
80 * NB: if you need the value to free it, read it before
81 * removing. ie: beware memory leaks!
82 * returns zero if advanced to end of table */
84 int
85 hashtable_iterator_remove(struct hashtable_itr *itr);
87 /*****************************************************************************/
88 /* search - overwrite the supplied iterator, to point to the entry
89 * matching the supplied key.
90 h points to the hashtable to be searched.
91 * returns zero if not found. */
92 int
93 hashtable_iterator_search(struct hashtable_itr *itr,
94 struct hashtable *h, void *k);
96 #define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \
97 int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \
98 { \
99 return (hashtable_iterator_search(i,h,k)); \
100 }
104 #endif /* __HASHTABLE_ITR_CWC22__*/