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