2 * Copyright (C) 1995-2007 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
27 * @note This has been named pset_new_new for now until all code has been
28 * changed to use this instead of the old deprecated pset_new functions!
29 * This version performs better than pset in terms of speed and memory
30 * usage and allows multiple iterators over the set
32 #ifndef FIRM_ADT_PSET_NEW_H
33 #define FIRM_ADT_PSET_NEW_H
35 #define HashSet pset_new_t
36 #define HashSetIterator pset_new_iterator_t
37 #define ValueType void*
42 #undef HashSetIterator
46 * Initializes a pset_new
48 * @param pset_new Pointer to allocated space for the pset_new
50 void pset_new_init(pset_new_t *pset_new);
53 * Initializes a pset_new
55 * @param pset_new Pointer to allocated space for the pset_new
56 * @param expected_elements Number of elements expected in the pset_new (roughly)
58 void pset_new_init_size(pset_new_t *pset_new, size_t expected_elements);
61 * Destroys a pset_new and frees the memory allocated for hashtable. The memory of
62 * the pset_new itself is not freed.
64 * @param pset_new Pointer to the pset_new
66 void pset_new_destroy(pset_new_t *pset_new);
69 * Inserts an element into a pset_new.
71 * @param pset_new Pointer to the pset_new
72 * @param ptr Pointer to insert into the pset_new
73 * @returns 1 if the pointer was inserted, 0 if it was already there
75 int pset_new_insert(pset_new_t *pset_new, void *ptr);
78 * Removes an element from a pset_new. Does nothing if the pset_new doesn't contain the
81 * @param pset_new Pointer to the pset_new
82 * @param ptr Pointer to remove from the pset_new
84 void pset_new_remove(pset_new_t *pset_new, const void *ptr);
87 * Tests whether a pset_new contains a pointer
89 * @param pset_new Pointer to the pset_new
90 * @param ptr The pointer to test
91 * @returns 1 @p pset_new contains the @p ptr, 0 otherwise
93 int pset_new_contains(const pset_new_t *pset_new, const void *ptr);
96 * Returns the number of pointers contained in the pset_new
98 * @param pset_new Pointer to the pset_new
99 * @returns Number of pointers contained in the pset_new
101 size_t pset_new_size(const pset_new_t *pset_new);
104 * Initializes a pset_new iterator. Sets the iterator before the first element in
107 * @param iterator Pointer to already allocated iterator memory
108 * @param pset_new Pointer to the pset_new
110 void pset_new_iterator_init(pset_new_iterator_t *iterator, const pset_new_t *pset_new);
113 * Advances the iterator and returns the current element or NULL if all elements
114 * in the pset_new have been processed.
115 * @attention It is not allowed to use pset_new_insert or pset_new_remove while
116 * iterating over a pset_new; pset_new_remove_iter is allowed.
118 * @param iterator Pointer to the pset_new iterator.
119 * @returns Next element in the pset_new or NULL
121 void* pset_new_iterator_next(pset_new_iterator_t *iterator);
124 * Removes the element that the iterator currently points to from the hashset.
126 * @param pset_new Pointer to the pset_new
127 * @param iterator Pointer to the iterator
129 void pset_new_remove_iterator(pset_new_t *pset_new, const pset_new_iterator_t *iterator);
132 * Convenience macro for iterating over a pset_new.
134 #define foreach_pset_new(pset_new, ptr, iter) \
135 for(pset_new_iterator_init(&iter, pset_new), \
136 ptr = pset_new_iterator_next(&iter); \
137 ptr != NULL; ptr = pset_new_iterator_next(&iter))