1 /* Copyright (C) 2002, 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk> */
3 #ifndef __HASHTABLE_ITR_CWC22__
4 #define __HASHTABLE_ITR_CWC22__
6 #include "hashtable_private.h" /* needed to enable inlining */
8 /*****************************************************************************/
9 /* This struct is only concrete here to allow the inlining of two of the
10 * accessor functions. */
20 /*****************************************************************************/
24 struct hashtable_itr *
25 hashtable_iterator(struct hashtable *h);
27 /*****************************************************************************/
28 /* hashtable_iterator_key
29 * - return the value of the (key,value) pair at the current position */
31 #ifdef HAVE_EXTERN_INLINE
33 hashtable_iterator_key(struct hashtable_itr *i)
39 hashtable_iterator_key(struct hashtable_itr *i);
42 /*****************************************************************************/
43 /* value - return the value of the (key,value) pair at the current position */
45 #ifdef HAVE_EXTERN_INLINE
47 hashtable_iterator_value(struct hashtable_itr *i)
53 hashtable_iterator_value(struct hashtable_itr *i);
56 /*****************************************************************************/
57 /* advance - advance the iterator to the next element
58 * returns zero if advanced to end of table */
61 hashtable_iterator_advance(struct hashtable_itr *itr);
63 /*****************************************************************************/
64 /* remove - remove current element and advance the iterator to the next element
65 * NB: if you need the value to free it, read it before
66 * removing. ie: beware memory leaks!
67 * returns zero if advanced to end of table */
70 hashtable_iterator_remove(struct hashtable_itr *itr);
72 /*****************************************************************************/
73 /* search - overwrite the supplied iterator, to point to the entry
74 * matching the supplied key.
75 h points to the hashtable to be searched.
76 * returns zero if not found. */
78 hashtable_iterator_search(struct hashtable_itr *itr,
79 struct hashtable *h, void *k);
81 #define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \
82 int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \
84 return (hashtable_iterator_search(i,h,k)); \
89 #endif /* __HASHTABLE_ITR_CWC22__*/
92 * Copyright (c) 2002, 2004, Christopher Clark
93 * All rights reserved.
95 * Redistribution and use in source and binary forms, with or without
96 * modification, are permitted provided that the following conditions
99 * * Redistributions of source code must retain the above copyright
100 * notice, this list of conditions and the following disclaimer.
102 * * Redistributions in binary form must reproduce the above copyright
103 * notice, this list of conditions and the following disclaimer in the
104 * documentation and/or other materials provided with the distribution.
106 * * Neither the name of the original author; nor the names of any contributors
107 * may be used to endorse or promote products derived from this software
108 * without specific prior written permission.
111 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
112 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
113 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
114 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
115 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
116 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
117 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
118 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
119 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
120 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
121 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.