changed printf format for size_t printing
[cparser] / adt / strset.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
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.
9  *
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.
14  *
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
18  * 02111-1307, USA.
19  */
20 #ifndef _FIRM_STRSET_H_
21 #define _FIRM_STRSET_H_
22
23 #define HashSet          strset_t
24 #define HashSetIterator  strset_iterator_t
25 #define HashSetEntry     strset_entry_t
26 #define ValueType        const char*
27 #include "hashset.h"
28 #undef ValueType
29 #undef HashSetEntry
30 #undef HashSetIterator
31 #undef HashSet
32
33 /**
34  * Initializes a strset
35  *
36  * @param strset   Pointer to allocated space for the strset
37  */
38 void strset_init(strset_t *strset);
39
40 /**
41  * Initializes a strset
42  *
43  * @param strset                Pointer to allocated space for the strset
44  * @param expected_elements   Number of elements expected in the strset (rougly)
45  */
46 void strset_init_size(strset_t *strset, size_t expected_elements);
47
48 /**
49  * Destroys a strset and frees the memory allocated for hashtable. The memory of
50  * the strset itself is not freed.
51  *
52  * @param strset   Pointer to the strset
53  */
54 void strset_destroy(strset_t *strset);
55
56 /**
57  * Inserts a string into a strset.
58  *
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
63  */
64 const char *strset_insert(strset_t *strset, const char *ptr);
65
66 /**
67  * Removes an element from a strset. Does nothing if the strset doesn't contain the
68  * element.
69  *
70  * @param strset   Pointer to the strset
71  * @param ptr    Pointer to remove from the strset
72  */
73 void strset_remove(strset_t *strset, const char *ptr);
74
75 /**
76  * Tests whether a strset contains a pointer
77  *
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
81  */
82 const char* strset_find(const strset_t *strset, const char *ptr);
83
84 /**
85  * Returns the number of pointers contained in the strset
86  *
87  * @param strset   Pointer to the strset
88  * @returns      Number of pointers contained in the strset
89  */
90 size_t strset_size(const strset_t *strset);
91
92 /**
93  * Initializes a strset iterator. Sets the iterator before the first element in
94  * the strset.
95  *
96  * @param iterator   Pointer to already allocated iterator memory
97  * @param strset       Pointer to the strset
98  */
99 void strset_iterator_init(strset_iterator_t *iterator, const strset_t *strset);
100
101 /**
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.
106  *
107  * @param iterator  Pointer to the strset iterator.
108  * @returns         Next element in the strset or NULL
109  */
110 const char *strset_iterator_next(strset_iterator_t *iterator);
111
112 /**
113  * Removes the string from the set that the iterator currently points to
114  *
115  * @param strset    Pointer to the strset
116  * @param iter      Pointer to the iterator
117  */
118 void strset_remove_iterator(strset_t *strset,
119                             const strset_iterator_t *iterator);
120
121 #endif