4 * @brief A hashset that contains pointers
5 * @author Matthias Braun
11 /* collides with libfirm... */
14 #define HashSet pset_t
15 #define HashSetIterator pset_iterator_t
16 #define ValueType void*
21 #undef HashSetIterator
27 * @param pset Pointer to allocated space for the pset
29 void pset_init(pset_t *pset);
34 * @param pset Pointer to allocated space for the pset
35 * @param expected_elements Number of elements expected in the pset (rougly)
37 void pset_init_size(pset_t *pset, size_t expected_elements);
40 * Destroys a pset and frees the memory allocated for hashtable. The memory of
41 * the pset itself is not freed.
43 * @param pset Pointer to the pset
45 void pset_destroy(pset_t *pset);
48 * Inserts an element into a pset.
50 * @param pset Pointer to the pset
51 * @param ptr Pointer to insert into the pset
52 * @returns 1 if the pointer was inserted, 0 if it was already there
54 int pset_insert(pset_t *pset, void *ptr);
57 * Removes an element from a pset. Does nothing if the pset doesn't contain the
60 * @param pset Pointer to the pset
61 * @param ptr Pointer to remove from the pset
63 void pset_remove(pset_t *pset, const void *ptr);
66 * Tests whether a pset contains a pointer
68 * @param pset Pointer to the pset
69 * @param ptr The pointer to test
70 * @returns 1 @p pset contains the @p ptr, 0 otherwise
72 int pset_contains(const pset_t *pset, const void *ptr);
75 * Returns the number of pointers contained in the pset
77 * @param pset Pointer to the pset
78 * @returns Number of pointers contained in the pset
80 size_t pset_size(const pset_t *pset);
83 * Initializes a pset iterator. Sets the iterator before the first element in
86 * @param iterator Pointer to already allocated iterator memory
87 * @param pset Pointer to the pset
89 void pset_iterator_init(pset_iterator_t *iterator, const pset_t *pset);
92 * Advances the iterator and returns the current element or NULL if all elements
93 * in the pset have been processed.
94 * @attention It is not allowed to use pset_insert or pset_remove while
95 * iterating over a pset; pset_remove_iter is allowed.
97 * @param iterator Pointer to the pset iterator.
98 * @returns Next element in the pset or NULL
100 void* pset_iterator_next(pset_iterator_t *iterator);
103 * Removes the element that the iterator currently points to from the hashset.
105 * @param pset Pointer to the pset
106 * @param iterator Pointer to the iterator
108 void pset_remove_iterator(pset_t *pset, const pset_iterator_t *iterator);