2 * This file is part of cparser.
3 * Copyright (C) 2007-2009 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
33 typedef struct strset_t strset_t;
34 typedef struct strset_iterator_t strset_iterator_t;
37 * Initializes a strset
39 * @param strset Pointer to allocated space for the strset
41 void strset_init(strset_t *strset);
44 * Initializes a strset
46 * @param strset Pointer to allocated space for the strset
47 * @param expected_elements Number of elements expected in the strset (rougly)
49 void strset_init_size(strset_t *strset, size_t expected_elements);
52 * Destroys a strset and frees the memory allocated for hashtable. The memory of
53 * the strset itself is not freed.
55 * @param strset Pointer to the strset
57 void strset_destroy(strset_t *strset);
60 * Inserts a string into a strset.
62 * @param strset Pointer to the strset
63 * @param ptr Pointer to insert into the strset
64 * @returns @p ptr if the string was inserted into the set,
65 * otherwise a pointer to the string already in the set
67 const char *strset_insert(strset_t *strset, const char *ptr);
70 * Removes an element from a strset. Does nothing if the strset doesn't contain the
73 * @param strset Pointer to the strset
74 * @param ptr Pointer to remove from the strset
76 void strset_remove(strset_t *strset, const char *ptr);
79 * Tests whether a strset contains a pointer
81 * @param strset Pointer to the strset
82 * @param ptr The pointer to test
83 * @returns 1 @p strset contains the @p ptr, 0 otherwise
85 const char* strset_find(const strset_t *strset, const char *ptr);
88 * Returns the number of pointers contained in the strset
90 * @param strset Pointer to the strset
91 * @returns Number of pointers contained in the strset
93 size_t strset_size(const strset_t *strset);
96 * Initializes a strset iterator. Sets the iterator before the first element in
99 * @param iterator Pointer to already allocated iterator memory
100 * @param strset Pointer to the strset
102 void strset_iterator_init(strset_iterator_t *iterator, const strset_t *strset);
105 * Advances the iterator and returns the current element or NULL if all elements
106 * in the strset have been processed.
107 * @attention It is not allowed to use strset_insert or strset_remove while
108 * iterating over a strset.
110 * @param iterator Pointer to the strset iterator.
111 * @returns Next element in the strset or NULL
113 const char *strset_iterator_next(strset_iterator_t *iterator);
116 * Removes the string from the set that the iterator currently points to
118 * @param strset Pointer to the strset
119 * @param iter Pointer to the iterator
121 void strset_remove_iterator(strset_t *strset,
122 const strset_iterator_t *iterator);