parser: Remove the unused attribute alignment from struct declaration_specifiers_t.
[cparser] / adt / pset_new.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @date    17.03.2007
9  * @brief   hashset containing pointers
10  * @author  Matthias Braun
11  *
12  * @note This has been named pset_new_new for now until all code has been
13  *       changed to use this instead of the old deprecated pset_new functions!
14  *       This version performs better than pset in terms of speed and memory
15  *       usage and allows multiple iterators over the set
16  */
17 #ifndef FIRM_ADT_PSET_NEW_H
18 #define FIRM_ADT_PSET_NEW_H
19
20 #include <stdbool.h>
21
22 /** @cond PRIVATE */
23
24 #define HashSet          pset_new_t
25 #define HashSetIterator  pset_new_iterator_t
26 #define ValueType        void*
27 #define DO_REHASH
28 #include "hashset.h"
29 #undef DO_REHASH
30 #undef HashSet
31 #undef HashSetIterator
32 #undef ValueType
33
34 /** @endcond */
35
36 /** a pointer (hash)set */
37 typedef struct pset_new_t           pset_new_t;
38 /** iterator over a pointer set.
39  * @see #pset_new_t */
40 typedef struct pset_new_iterator_t  pset_new_iterator_t;
41
42 /**
43  * Initializes a pset_new
44  *
45  * @param pset_new   Pointer to allocated space for the pset_new
46  */
47 void pset_new_init(pset_new_t *pset_new);
48
49 /**
50  * Initializes a pset_new
51  *
52  * @param pset_new            Pointer to allocated space for the pset_new
53  * @param expected_elements   Number of elements expected in the pset_new (roughly)
54  */
55 void pset_new_init_size(pset_new_t *pset_new, size_t expected_elements);
56
57 /**
58  * Destroys a pset_new and frees the memory allocated for hashtable. The memory of
59  * the pset_new itself is not freed.
60  *
61  * @param pset_new   Pointer to the pset_new
62  */
63 void pset_new_destroy(pset_new_t *pset_new);
64
65 /**
66  * Inserts an element into a pset_new.
67  *
68  * @param pset_new   Pointer to the pset_new
69  * @param ptr    Pointer to insert into the pset_new
70  * @returns      true if the pointer was inserted, false if it was already there
71  */
72 bool pset_new_insert(pset_new_t *pset_new, void *ptr);
73
74 /**
75  * Removes an element from a pset_new. Does nothing if the pset_new doesn't contain the
76  * element.
77  *
78  * @param pset_new   Pointer to the pset_new
79  * @param ptr    Pointer to remove from the pset_new
80  */
81 void pset_new_remove(pset_new_t *pset_new, const void *ptr);
82
83 /**
84  * Tests whether a pset_new contains a pointer
85  *
86  * @param pset_new   Pointer to the pset_new
87  * @param ptr    The pointer to test
88  */
89 bool pset_new_contains(const pset_new_t *pset_new, const void *ptr);
90
91 /**
92  * Returns the number of pointers contained in the pset_new
93  *
94  * @param pset_new   Pointer to the pset_new
95  * @returns      Number of pointers contained in the pset_new
96  */
97 size_t pset_new_size(const pset_new_t *pset_new);
98
99 /**
100  * Initializes a pset_new iterator. Sets the iterator before the first element in
101  * the pset_new.
102  *
103  * @param iterator   Pointer to already allocated iterator memory
104  * @param pset_new       Pointer to the pset_new
105  */
106 void pset_new_iterator_init(pset_new_iterator_t *iterator, const pset_new_t *pset_new);
107
108 /**
109  * Advances the iterator and returns the current element or NULL if all elements
110  * in the pset_new have been processed.
111  * @attention It is not allowed to use pset_new_insert or pset_new_remove while
112  *            iterating over a pset_new; pset_new_remove_iter is allowed.
113  *
114  * @param iterator  Pointer to the pset_new iterator.
115  * @returns         Next element in the pset_new or NULL
116  */
117 void* pset_new_iterator_next(pset_new_iterator_t *iterator);
118
119 /**
120  * Removes the element that the iterator currently points to from the hashset.
121  *
122  * @param pset_new      Pointer to the pset_new
123  * @param iterator  Pointer to the iterator
124  */
125 void pset_new_remove_iterator(pset_new_t *pset_new, const pset_new_iterator_t *iterator);
126
127 /**
128  * Convenience macro for iterating over a pset_new.
129  */
130 #define foreach_pset_new(pset_new, type, ptr, iter)    \
131         for(pset_new_iterator_init(&iter, pset_new), \
132                 ptr = (type) pset_new_iterator_next(&iter);     \
133                 ptr != NULL; ptr = (type) pset_new_iterator_next(&iter))
134
135 #endif