2 * This file is part of cparser.
3 * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 * @brief A hashset that contains pointers
25 * @author Matthias Braun
31 /* collides with libfirm... */
34 #define HashSet pset_t
35 #define HashSetIterator pset_iterator_t
36 #define ValueType void*
41 #undef HashSetIterator
47 * @param pset Pointer to allocated space for the pset
49 void pset_init(pset_t *pset);
54 * @param pset Pointer to allocated space for the pset
55 * @param expected_elements Number of elements expected in the pset (rougly)
57 void pset_init_size(pset_t *pset, size_t expected_elements);
60 * Destroys a pset and frees the memory allocated for hashtable. The memory of
61 * the pset itself is not freed.
63 * @param pset Pointer to the pset
65 void pset_destroy(pset_t *pset);
68 * Inserts an element into a pset.
70 * @param pset Pointer to the pset
71 * @param ptr Pointer to insert into the pset
72 * @returns 1 if the pointer was inserted, 0 if it was already there
74 int pset_insert(pset_t *pset, void *ptr);
77 * Removes an element from a pset. Does nothing if the pset doesn't contain the
80 * @param pset Pointer to the pset
81 * @param ptr Pointer to remove from the pset
83 void pset_remove(pset_t *pset, const void *ptr);
86 * Tests whether a pset contains a pointer
88 * @param pset Pointer to the pset
89 * @param ptr The pointer to test
90 * @returns 1 @p pset contains the @p ptr, 0 otherwise
92 int pset_contains(const pset_t *pset, const void *ptr);
95 * Returns the number of pointers contained in the pset
97 * @param pset Pointer to the pset
98 * @returns Number of pointers contained in the pset
100 size_t pset_size(const pset_t *pset);
103 * Initializes a pset iterator. Sets the iterator before the first element in
106 * @param iterator Pointer to already allocated iterator memory
107 * @param pset Pointer to the pset
109 void pset_iterator_init(pset_iterator_t *iterator, const pset_t *pset);
112 * Advances the iterator and returns the current element or NULL if all elements
113 * in the pset have been processed.
114 * @attention It is not allowed to use pset_insert or pset_remove while
115 * iterating over a pset; pset_remove_iter is allowed.
117 * @param iterator Pointer to the pset iterator.
118 * @returns Next element in the pset or NULL
120 void* pset_iterator_next(pset_iterator_t *iterator);
123 * Removes the element that the iterator currently points to from the hashset.
125 * @param pset Pointer to the pset
126 * @param iterator Pointer to the iterator
128 void pset_remove_iterator(pset_t *pset, const pset_iterator_t *iterator);