2 * This file is part of cparser.
3 * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
5 #ifndef _FIRM_STRSET_H_
6 #define _FIRM_STRSET_H_
8 #define HashSet strset_t
9 #define HashSetIterator strset_iterator_t
10 #define HashSetEntry strset_entry_t
11 #define ValueType const char*
15 #undef HashSetIterator
18 typedef struct strset_t strset_t;
19 typedef struct strset_iterator_t strset_iterator_t;
22 * Initializes a strset
24 * @param strset Pointer to allocated space for the strset
26 void strset_init(strset_t *strset);
29 * Initializes a strset
31 * @param strset Pointer to allocated space for the strset
32 * @param expected_elements Number of elements expected in the strset (rougly)
34 void strset_init_size(strset_t *strset, size_t expected_elements);
37 * Destroys a strset and frees the memory allocated for hashtable. The memory of
38 * the strset itself is not freed.
40 * @param strset Pointer to the strset
42 void strset_destroy(strset_t *strset);
45 * Inserts a string into a strset.
47 * @param strset Pointer to the strset
48 * @param ptr Pointer to insert into the strset
49 * @returns @p ptr if the string was inserted into the set,
50 * otherwise a pointer to the string already in the set
52 const char *strset_insert(strset_t *strset, const char *ptr);
55 * Removes an element from a strset. Does nothing if the strset doesn't contain the
58 * @param strset Pointer to the strset
59 * @param ptr Pointer to remove from the strset
61 void strset_remove(strset_t *strset, const char *ptr);
64 * Tests whether a strset contains a pointer
66 * @param strset Pointer to the strset
67 * @param ptr The pointer to test
68 * @returns 1 @p strset contains the @p ptr, 0 otherwise
70 const char* strset_find(const strset_t *strset, const char *ptr);
73 * Returns the number of pointers contained in the strset
75 * @param strset Pointer to the strset
76 * @returns Number of pointers contained in the strset
78 size_t strset_size(const strset_t *strset);
81 * Initializes a strset iterator. Sets the iterator before the first element in
84 * @param iterator Pointer to already allocated iterator memory
85 * @param strset Pointer to the strset
87 void strset_iterator_init(strset_iterator_t *iterator, const strset_t *strset);
90 * Advances the iterator and returns the current element or NULL if all elements
91 * in the strset have been processed.
92 * @attention It is not allowed to use strset_insert or strset_remove while
93 * iterating over a strset.
95 * @param iterator Pointer to the strset iterator.
96 * @returns Next element in the strset or NULL
98 const char *strset_iterator_next(strset_iterator_t *iterator);
101 * Removes the string from the set that the iterator currently points to
103 * @param strset Pointer to the strset
104 * @param iter Pointer to the iterator
106 void strset_remove_iterator(strset_t *strset,
107 const strset_iterator_t *iterator);