fix cases where compoundlits are constant/get an entity
[cparser] / adt / pset_new.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @date    17.03.2007
23  * @brief   hashset containing pointers
24  * @author  Matthias Braun
25  *
26  * @note This has been named pset_new_new for now until all code has been
27  *       changed to use this instead of the old deprecated pset_new functions!
28  *       This version performs better than pset in terms of speed and memory
29  *       usage and allows multiple iterators over the set
30  */
31 #ifndef FIRM_ADT_PSET_NEW_H
32 #define FIRM_ADT_PSET_NEW_H
33
34 #include <stdbool.h>
35
36 /** @cond PRIVATE */
37
38 #define HashSet          pset_new_t
39 #define HashSetIterator  pset_new_iterator_t
40 #define ValueType        void*
41 #define DO_REHASH
42 #include "hashset.h"
43 #undef DO_REHASH
44 #undef HashSet
45 #undef HashSetIterator
46 #undef ValueType
47
48 /** @endcond */
49
50 /** a pointer (hash)set */
51 typedef struct pset_new_t           pset_new_t;
52 /** iterator over a pointer set.
53  * @see #pset_new_t */
54 typedef struct pset_new_iterator_t  pset_new_iterator_t;
55
56 /**
57  * Initializes a pset_new
58  *
59  * @param pset_new   Pointer to allocated space for the pset_new
60  */
61 void pset_new_init(pset_new_t *pset_new);
62
63 /**
64  * Initializes a pset_new
65  *
66  * @param pset_new            Pointer to allocated space for the pset_new
67  * @param expected_elements   Number of elements expected in the pset_new (roughly)
68  */
69 void pset_new_init_size(pset_new_t *pset_new, size_t expected_elements);
70
71 /**
72  * Destroys a pset_new and frees the memory allocated for hashtable. The memory of
73  * the pset_new itself is not freed.
74  *
75  * @param pset_new   Pointer to the pset_new
76  */
77 void pset_new_destroy(pset_new_t *pset_new);
78
79 /**
80  * Inserts an element into a pset_new.
81  *
82  * @param pset_new   Pointer to the pset_new
83  * @param ptr    Pointer to insert into the pset_new
84  * @returns      true if the pointer was inserted, false if it was already there
85  */
86 bool pset_new_insert(pset_new_t *pset_new, void *ptr);
87
88 /**
89  * Removes an element from a pset_new. Does nothing if the pset_new doesn't contain the
90  * element.
91  *
92  * @param pset_new   Pointer to the pset_new
93  * @param ptr    Pointer to remove from the pset_new
94  */
95 void pset_new_remove(pset_new_t *pset_new, const void *ptr);
96
97 /**
98  * Tests whether a pset_new contains a pointer
99  *
100  * @param pset_new   Pointer to the pset_new
101  * @param ptr    The pointer to test
102  */
103 bool pset_new_contains(const pset_new_t *pset_new, const void *ptr);
104
105 /**
106  * Returns the number of pointers contained in the pset_new
107  *
108  * @param pset_new   Pointer to the pset_new
109  * @returns      Number of pointers contained in the pset_new
110  */
111 size_t pset_new_size(const pset_new_t *pset_new);
112
113 /**
114  * Initializes a pset_new iterator. Sets the iterator before the first element in
115  * the pset_new.
116  *
117  * @param iterator   Pointer to already allocated iterator memory
118  * @param pset_new       Pointer to the pset_new
119  */
120 void pset_new_iterator_init(pset_new_iterator_t *iterator, const pset_new_t *pset_new);
121
122 /**
123  * Advances the iterator and returns the current element or NULL if all elements
124  * in the pset_new have been processed.
125  * @attention It is not allowed to use pset_new_insert or pset_new_remove while
126  *            iterating over a pset_new; pset_new_remove_iter is allowed.
127  *
128  * @param iterator  Pointer to the pset_new iterator.
129  * @returns         Next element in the pset_new or NULL
130  */
131 void* pset_new_iterator_next(pset_new_iterator_t *iterator);
132
133 /**
134  * Removes the element that the iterator currently points to from the hashset.
135  *
136  * @param pset_new      Pointer to the pset_new
137  * @param iterator  Pointer to the iterator
138  */
139 void pset_new_remove_iterator(pset_new_t *pset_new, const pset_new_iterator_t *iterator);
140
141 /**
142  * Convenience macro for iterating over a pset_new.
143  */
144 #define foreach_pset_new(pset_new, type, ptr, iter)    \
145         for(pset_new_iterator_init(&iter, pset_new), \
146                 ptr = (type) pset_new_iterator_next(&iter);     \
147                 ptr != NULL; ptr = (type) pset_new_iterator_next(&iter))
148
149 #endif