Initial import of c parser
[cparser] / adt / strset.h
1 #ifndef _FIRM_STRSET_H_
2 #define _FIRM_STRSET_H_
3
4 #define HashSet          strset_t
5 #define HashSetIterator  strset_iterator_t
6 #define HashSetEntry     strset_entry_t
7 #define ValueType        const char*
8 #include "hashset.h"
9 #undef ValueType
10 #undef HashSetEntry
11 #undef HashSetIterator
12 #undef HashSet
13
14 /**
15  * Initializes a strset
16  *
17  * @param strset   Pointer to allocated space for the strset
18  */
19 void strset_init(strset_t *strset);
20
21 /**
22  * Initializes a strset
23  *
24  * @param strset                Pointer to allocated space for the strset
25  * @param expected_elements   Number of elements expected in the strset (rougly)
26  */
27 void strset_init_size(strset_t *strset, size_t expected_elements);
28
29 /**
30  * Destroys a strset and frees the memory allocated for hashtable. The memory of
31  * the strset itself is not freed.
32  *
33  * @param strset   Pointer to the strset
34  */
35 void strset_destroy(strset_t *strset);
36
37 /**
38  * Inserts a string into a strset.
39  *
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
44  */
45 const char *strset_insert(strset_t *strset, const char *ptr);
46
47 /**
48  * Removes an element from a strset. Does nothing if the strset doesn't contain the
49  * element.
50  *
51  * @param strset   Pointer to the strset
52  * @param ptr    Pointer to remove from the strset
53  */
54 void strset_remove(strset_t *strset, const char *ptr);
55
56 /**
57  * Tests whether a strset contains a pointer
58  *
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
62  */
63 const char* strset_find(const strset_t *strset, const char *ptr);
64
65 /**
66  * Returns the number of pointers contained in the strset
67  *
68  * @param strset   Pointer to the strset
69  * @returns      Number of pointers contained in the strset
70  */
71 size_t strset_size(const strset_t *strset);
72
73 /**
74  * Initializes a strset iterator. Sets the iterator before the first element in
75  * the strset.
76  *
77  * @param iterator   Pointer to already allocated iterator memory
78  * @param strset       Pointer to the strset
79  */
80 void strset_iterator_init(strset_iterator_t *iterator, const strset_t *strset);
81
82 /**
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.
87  *
88  * @param iterator  Pointer to the strset iterator.
89  * @returns         Next element in the strset or NULL
90  */
91 const char *strset_iterator_next(strset_iterator_t *iterator);
92
93 /**
94  * Removes the string from the set that the iterator currently points to
95  *
96  * @param strset    Pointer to the strset
97  * @param iter      Pointer to the iterator
98  */
99 void strset_remove_iterator(strset_t *strset,
100                             const strset_iterator_t *iterator);
101
102 #endif