Debian Codegraph @

runtime/hashtable_itr.h

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