2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
23 * @brief hashset containing pointers
24 * @author Matthias Braun
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
31 #ifndef FIRM_ADT_PSET_NEW_H
32 #define FIRM_ADT_PSET_NEW_H
36 #define HashSet pset_new_t
37 #define HashSetIterator pset_new_iterator_t
38 #define ValueType void*
43 #undef HashSetIterator
46 typedef struct pset_new_t pset_new_t;
47 typedef struct pset_new_iterator_t pset_new_iterator_t;
50 * Initializes a pset_new
52 * @param pset_new Pointer to allocated space for the pset_new
54 FIRM_API void pset_new_init(pset_new_t *pset_new);
57 * Initializes a pset_new
59 * @param pset_new Pointer to allocated space for the pset_new
60 * @param expected_elements Number of elements expected in the pset_new (roughly)
62 FIRM_API void pset_new_init_size(pset_new_t *pset_new, size_t expected_elements);
65 * Destroys a pset_new and frees the memory allocated for hashtable. The memory of
66 * the pset_new itself is not freed.
68 * @param pset_new Pointer to the pset_new
70 FIRM_API void pset_new_destroy(pset_new_t *pset_new);
73 * Inserts an element into a pset_new.
75 * @param pset_new Pointer to the pset_new
76 * @param ptr Pointer to insert into the pset_new
77 * @returns 1 if the pointer was inserted, 0 if it was already there
79 FIRM_API int pset_new_insert(pset_new_t *pset_new, void *ptr);
82 * Removes an element from a pset_new. Does nothing if the pset_new doesn't contain the
85 * @param pset_new Pointer to the pset_new
86 * @param ptr Pointer to remove from the pset_new
88 FIRM_API void pset_new_remove(pset_new_t *pset_new, const void *ptr);
91 * Tests whether a pset_new contains a pointer
93 * @param pset_new Pointer to the pset_new
94 * @param ptr The pointer to test
95 * @returns 1 @p pset_new contains the @p ptr, 0 otherwise
97 FIRM_API int pset_new_contains(const pset_new_t *pset_new, const void *ptr);
100 * Returns the number of pointers contained in the pset_new
102 * @param pset_new Pointer to the pset_new
103 * @returns Number of pointers contained in the pset_new
105 FIRM_API size_t pset_new_size(const pset_new_t *pset_new);
108 * Initializes a pset_new iterator. Sets the iterator before the first element in
111 * @param iterator Pointer to already allocated iterator memory
112 * @param pset_new Pointer to the pset_new
114 FIRM_API void pset_new_iterator_init(pset_new_iterator_t *iterator, const pset_new_t *pset_new);
117 * Advances the iterator and returns the current element or NULL if all elements
118 * in the pset_new have been processed.
119 * @attention It is not allowed to use pset_new_insert or pset_new_remove while
120 * iterating over a pset_new; pset_new_remove_iter is allowed.
122 * @param iterator Pointer to the pset_new iterator.
123 * @returns Next element in the pset_new or NULL
125 FIRM_API void* pset_new_iterator_next(pset_new_iterator_t *iterator);
128 * Removes the element that the iterator currently points to from the hashset.
130 * @param pset_new Pointer to the pset_new
131 * @param iterator Pointer to the iterator
133 FIRM_API void pset_new_remove_iterator(pset_new_t *pset_new, const pset_new_iterator_t *iterator);
136 * Convenience macro for iterating over a pset_new.
138 #define foreach_pset_new(pset_new, type, ptr, iter) \
139 for(pset_new_iterator_init(&iter, pset_new), \
140 ptr = (type) pset_new_iterator_next(&iter); \
141 ptr != NULL; ptr = (type) pset_new_iterator_next(&iter))