Initial import of c parser
[cparser] / adt / pset.h
1 /**
2  * @file
3  * @date    17.03.2007
4  * @brief   A hashset that contains pointers
5  * @author  Matthias Braun
6  * @version $Id$
7  */
8 #ifndef _FIRM_PSET_H_
9 #define _FIRM_PSET_H_
10
11 /* collides with libfirm... */
12 #if 0
13
14 #define HashSet          pset_t
15 #define HashSetIterator  pset_iterator_t
16 #define ValueType        void*
17 #define DO_REHASH
18 #include "hashset.h"
19 #undef DO_REHASH
20 #undef HashSet
21 #undef HashSetIterator
22 #undef ValueType
23
24 /**
25  * Initializes a pset
26  *
27  * @param pset   Pointer to allocated space for the pset
28  */
29 void pset_init(pset_t *pset);
30
31 /**
32  * Initializes a pset
33  *
34  * @param pset                Pointer to allocated space for the pset
35  * @param expected_elements   Number of elements expected in the pset (rougly)
36  */
37 void pset_init_size(pset_t *pset, size_t expected_elements);
38
39 /**
40  * Destroys a pset and frees the memory allocated for hashtable. The memory of
41  * the pset itself is not freed.
42  *
43  * @param pset   Pointer to the pset
44  */
45 void pset_destroy(pset_t *pset);
46
47 /**
48  * Inserts an element into a pset.
49  *
50  * @param pset   Pointer to the pset
51  * @param ptr    Pointer to insert into the pset
52  * @returns      1 if the pointer was inserted, 0 if it was already there
53  */
54 int pset_insert(pset_t *pset, void *ptr);
55
56 /**
57  * Removes an element from a pset. Does nothing if the pset doesn't contain the
58  * element.
59  *
60  * @param pset   Pointer to the pset
61  * @param ptr    Pointer to remove from the pset
62  */
63 void pset_remove(pset_t *pset, const void *ptr);
64
65 /**
66  * Tests whether a pset contains a pointer
67  *
68  * @param pset   Pointer to the pset
69  * @param ptr    The pointer to test
70  * @returns      1 @p pset contains the @p ptr, 0 otherwise
71  */
72 int pset_contains(const pset_t *pset, const void *ptr);
73
74 /**
75  * Returns the number of pointers contained in the pset
76  *
77  * @param pset   Pointer to the pset
78  * @returns      Number of pointers contained in the pset
79  */
80 size_t pset_size(const pset_t *pset);
81
82 /**
83  * Initializes a pset iterator. Sets the iterator before the first element in
84  * the pset.
85  *
86  * @param iterator   Pointer to already allocated iterator memory
87  * @param pset       Pointer to the pset
88  */
89 void pset_iterator_init(pset_iterator_t *iterator, const pset_t *pset);
90
91 /**
92  * Advances the iterator and returns the current element or NULL if all elements
93  * in the pset have been processed.
94  * @attention It is not allowed to use pset_insert or pset_remove while
95  *            iterating over a pset; pset_remove_iter is allowed.
96  *
97  * @param iterator  Pointer to the pset iterator.
98  * @returns         Next element in the pset or NULL
99  */
100 void* pset_iterator_next(pset_iterator_t *iterator);
101
102 /**
103  * Removes the element that the iterator currently points to from the hashset.
104  *
105  * @param pset      Pointer to the pset
106  * @param iterator  Pointer to the iterator
107  */
108 void pset_remove_iterator(pset_t *pset, const pset_iterator_t *iterator);
109 #endif
110
111 #endif