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
20 #ifndef _FIRM_STRSET_H_
21 #define _FIRM_STRSET_H_
23 #define HashSet strset_t
24 #define HashSetIterator strset_iterator_t
25 #define HashSetEntry strset_entry_t
26 #define ValueType const char*
30 #undef HashSetIterator
34 * Initializes a strset
36 * @param strset Pointer to allocated space for the strset
38 void strset_init(strset_t *strset);
41 * Initializes a strset
43 * @param strset Pointer to allocated space for the strset
44 * @param expected_elements Number of elements expected in the strset (rougly)
46 void strset_init_size(strset_t *strset, size_t expected_elements);
49 * Destroys a strset and frees the memory allocated for hashtable. The memory of
50 * the strset itself is not freed.
52 * @param strset Pointer to the strset
54 void strset_destroy(strset_t *strset);
57 * Inserts a string into a strset.
59 * @param strset Pointer to the strset
60 * @param ptr Pointer to insert into the strset
61 * @returns @p ptr if the string was inserted into the set,
62 * otherwise a pointer to the string already in the set
64 const char *strset_insert(strset_t *strset, const char *ptr);
67 * Removes an element from a strset. Does nothing if the strset doesn't contain the
70 * @param strset Pointer to the strset
71 * @param ptr Pointer to remove from the strset
73 void strset_remove(strset_t *strset, const char *ptr);
76 * Tests whether a strset contains a pointer
78 * @param strset Pointer to the strset
79 * @param ptr The pointer to test
80 * @returns 1 @p strset contains the @p ptr, 0 otherwise
82 const char* strset_find(const strset_t *strset, const char *ptr);
85 * Returns the number of pointers contained in the strset
87 * @param strset Pointer to the strset
88 * @returns Number of pointers contained in the strset
90 size_t strset_size(const strset_t *strset);
93 * Initializes a strset iterator. Sets the iterator before the first element in
96 * @param iterator Pointer to already allocated iterator memory
97 * @param strset Pointer to the strset
99 void strset_iterator_init(strset_iterator_t *iterator, const strset_t *strset);
102 * Advances the iterator and returns the current element or NULL if all elements
103 * in the strset have been processed.
104 * @attention It is not allowed to use strset_insert or strset_remove while
105 * iterating over a strset.
107 * @param iterator Pointer to the strset iterator.
108 * @returns Next element in the strset or NULL
110 const char *strset_iterator_next(strset_iterator_t *iterator);
113 * Removes the string from the set that the iterator currently points to
115 * @param strset Pointer to the strset
116 * @param iter Pointer to the iterator
118 void strset_remove_iterator(strset_t *strset,
119 const strset_iterator_t *iterator);