struct_assignment: move and improve handling smatch_data/*.clears_argument
[smatch.git] / cwchash / hashtable_itr.h
blobeea699a72c81012b11ad3b4262aff957d94f1ef0
1 /* Copyright (C) 2002, 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk> */
3 #ifndef __HASHTABLE_ITR_CWC22__
4 #define __HASHTABLE_ITR_CWC22__
5 #include "hashtable.h"
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. */
11 struct hashtable_itr
13 struct hashtable *h;
14 struct entry *e;
15 struct entry *parent;
16 unsigned int index;
20 /*****************************************************************************/
21 /* hashtable_iterator
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 extern inline void *
32 hashtable_iterator_key(struct hashtable_itr *i)
34 return i->e->k;
37 /*****************************************************************************/
38 /* value - return the value of the (key,value) pair at the current position */
40 extern inline void *
41 hashtable_iterator_value(struct hashtable_itr *i)
43 return i->e->v;
46 /*****************************************************************************/
47 /* advance - advance the iterator to the next element
48 * returns zero if advanced to end of table */
50 int
51 hashtable_iterator_advance(struct hashtable_itr *itr);
53 /*****************************************************************************/
54 /* remove - remove current element and advance the iterator to the next element
55 * NB: if you need the value to free it, read it before
56 * removing. ie: beware memory leaks!
57 * returns zero if advanced to end of table */
59 int
60 hashtable_iterator_remove(struct hashtable_itr *itr);
62 /*****************************************************************************/
63 /* search - overwrite the supplied iterator, to point to the entry
64 * matching the supplied key.
65 h points to the hashtable to be searched.
66 * returns zero if not found. */
67 int
68 hashtable_iterator_search(struct hashtable_itr *itr,
69 struct hashtable *h, void *k);
71 #define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \
72 int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \
73 { \
74 return (hashtable_iterator_search(i,h,k)); \
79 #endif /* __HASHTABLE_ITR_CWC22__*/
82 * Copyright (c) 2002, 2004, Christopher Clark
83 * All rights reserved.
85 * Redistribution and use in source and binary forms, with or without
86 * modification, are permitted provided that the following conditions
87 * are met:
89 * * Redistributions of source code must retain the above copyright
90 * notice, this list of conditions and the following disclaimer.
92 * * Redistributions in binary form must reproduce the above copyright
93 * notice, this list of conditions and the following disclaimer in the
94 * documentation and/or other materials provided with the distribution.
96 * * Neither the name of the original author; nor the names of any contributors
97 * may be used to endorse or promote products derived from this software
98 * without specific prior written permission.
101 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
102 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
103 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
104 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
105 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
106 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
107 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
108 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
109 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
110 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
111 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.