1 #ifndef _FIRM_STRSET_H_
2 #define _FIRM_STRSET_H_
4 #define HashSet strset_t
5 #define HashSetIterator strset_iterator_t
6 #define HashSetEntry strset_entry_t
7 #define ValueType const char*
11 #undef HashSetIterator
15 * Initializes a strset
17 * @param strset Pointer to allocated space for the strset
19 void strset_init(strset_t *strset);
22 * Initializes a strset
24 * @param strset Pointer to allocated space for the strset
25 * @param expected_elements Number of elements expected in the strset (rougly)
27 void strset_init_size(strset_t *strset, size_t expected_elements);
30 * Destroys a strset and frees the memory allocated for hashtable. The memory of
31 * the strset itself is not freed.
33 * @param strset Pointer to the strset
35 void strset_destroy(strset_t *strset);
38 * Inserts a string into a strset.
40 * @param strset Pointer to the strset
41 * @param ptr Pointer to insert into the strset
42 * @returns @p ptr if the string was inserted into the set,
43 * otherwise a pointer to the string already in the set
45 const char *strset_insert(strset_t *strset, const char *ptr);
48 * Removes an element from a strset. Does nothing if the strset doesn't contain the
51 * @param strset Pointer to the strset
52 * @param ptr Pointer to remove from the strset
54 void strset_remove(strset_t *strset, const char *ptr);
57 * Tests whether a strset contains a pointer
59 * @param strset Pointer to the strset
60 * @param ptr The pointer to test
61 * @returns 1 @p strset contains the @p ptr, 0 otherwise
63 const char* strset_find(const strset_t *strset, const char *ptr);
66 * Returns the number of pointers contained in the strset
68 * @param strset Pointer to the strset
69 * @returns Number of pointers contained in the strset
71 size_t strset_size(const strset_t *strset);
74 * Initializes a strset iterator. Sets the iterator before the first element in
77 * @param iterator Pointer to already allocated iterator memory
78 * @param strset Pointer to the strset
80 void strset_iterator_init(strset_iterator_t *iterator, const strset_t *strset);
83 * Advances the iterator and returns the current element or NULL if all elements
84 * in the strset have been processed.
85 * @attention It is not allowed to use strset_insert or strset_remove while
86 * iterating over a strset.
88 * @param iterator Pointer to the strset iterator.
89 * @returns Next element in the strset or NULL
91 const char *strset_iterator_next(strset_iterator_t *iterator);
94 * Removes the string from the set that the iterator currently points to
96 * @param strset Pointer to the strset
97 * @param iter Pointer to the iterator
99 void strset_remove_iterator(strset_t *strset,
100 const strset_iterator_t *iterator);