530f9adcaeadf0563bd8364e3bfb75d1747ef5b8
[libfirm] / ir / adt / pset_new.h
1 /**
2  * @file
3  * @date    17.03.2007
4  * @brief   A hashset that contains pointers
5  * @author  Matthias Braun
6  * @version $Id: pset_new.h 169 2007-04-03 01:01:09Z uxsm $
7  *
8  * NOTE: This has been named pset_new_new for now until all code has been changed
9  *       to use this instead of the old deprecated pset_new functions!
10  */
11 #ifndef _FIRM_PSET_NEW_H_
12 #define _FIRM_PSET_NEW_H_
13
14 #define HashSet          pset_new_t
15 #define HashSetIterator  pset_new_iterator_t
16 #define ValueType        void*
17 #define DO_REHASH
18 #include "hashset.h"
19 #undef DO_REHASH
20 #undef HashSet
21 #undef HashSetIterator
22 #undef ValueType
23
24 /**
25  * Initializes a pset_new
26  *
27  * @param pset_new   Pointer to allocated space for the pset_new
28  */
29 void pset_new_init(pset_new_t *pset_new);
30
31 /**
32  * Initializes a pset_new
33  *
34  * @param pset_new                Pointer to allocated space for the pset_new
35  * @param expected_elements   Number of elements expected in the pset_new (rougly)
36  */
37 void pset_new_init_size(pset_new_t *pset_new, size_t expected_elements);
38
39 /**
40  * Destroys a pset_new and frees the memory allocated for hashtable. The memory of
41  * the pset_new itself is not freed.
42  *
43  * @param pset_new   Pointer to the pset_new
44  */
45 void pset_new_destroy(pset_new_t *pset_new);
46
47 /**
48  * Inserts an element into a pset_new.
49  *
50  * @param pset_new   Pointer to the pset_new
51  * @param ptr    Pointer to insert into the pset_new
52  * @returns      1 if the pointer was inserted, 0 if it was already there
53  */
54 int pset_new_insert(pset_new_t *pset_new, void *ptr);
55
56 /**
57  * Removes an element from a pset_new. Does nothing if the pset_new doesn't contain the
58  * element.
59  *
60  * @param pset_new   Pointer to the pset_new
61  * @param ptr    Pointer to remove from the pset_new
62  */
63 void pset_new_remove(pset_new_t *pset_new, const void *ptr);
64
65 /**
66  * Tests whether a pset_new contains a pointer
67  *
68  * @param pset_new   Pointer to the pset_new
69  * @param ptr    The pointer to test
70  * @returns      1 @p pset_new contains the @p ptr, 0 otherwise
71  */
72 int pset_new_contains(const pset_new_t *pset_new, const void *ptr);
73
74 /**
75  * Returns the number of pointers contained in the pset_new
76  *
77  * @param pset_new   Pointer to the pset_new
78  * @returns      Number of pointers contained in the pset_new
79  */
80 size_t pset_new_size(const pset_new_t *pset_new);
81
82 /**
83  * Initializes a pset_new iterator. Sets the iterator before the first element in
84  * the pset_new.
85  *
86  * @param iterator   Pointer to already allocated iterator memory
87  * @param pset_new       Pointer to the pset_new
88  */
89 void pset_new_iterator_init(pset_new_iterator_t *iterator, const pset_new_t *pset_new);
90
91 /**
92  * Advances the iterator and returns the current element or NULL if all elements
93  * in the pset_new have been processed.
94  * @attention It is not allowed to use pset_new_insert or pset_new_remove while
95  *            iterating over a pset_new; pset_new_remove_iter is allowed.
96  *
97  * @param iterator  Pointer to the pset_new iterator.
98  * @returns         Next element in the pset_new or NULL
99  */
100 void* pset_new_iterator_next(pset_new_iterator_t *iterator);
101
102 /**
103  * Removes the element that the iterator currently points to from the hashset.
104  *
105  * @param pset_new      Pointer to the pset_new
106  * @param iterator  Pointer to the iterator
107  */
108 void pset_new_remove_iterator(pset_new_t *pset_new, const pset_new_iterator_t *iterator);
109
110 /**
111  * Convenience macro for iterating over a pset_new.
112  */
113 #define foreach_pset_new(pset_new, ptr, iter)    \
114         for(pset_new_iterator_init(&iter, pset_new), \
115                 ptr = pset_new_iterator_next(&iter);     \
116                 ptr != NULL; ptr = pset_new_iterator_next(&iter))
117
118 #endif /* _FIRM_PSET_NEW_H_ */