libFirm
pset.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19 
26 #ifndef FIRM_ADT_PSET_H
27 #define FIRM_ADT_PSET_H
28 
29 #include <stddef.h>
30 
31 #include "hashptr.h"
32 
33 #include "../begin.h"
34 
49 FIRM_API int pset_default_ptr_cmp(const void *x, const void *y);
50 
59 typedef struct pset pset;
60 
62 #define pset_insert_ptr(set,key) pset_insert(set, key, hash_ptr(key))
63 
64 #define pset_hinsert_ptr(set,key) pset_hinsert(set, key, hash_ptr(key))
65 
66 #define pset_remove_ptr(set,key) pset_remove(set, key, hash_ptr(key))
67 
68 #define pset_find_ptr(set,key) pset_find(set, key, hash_ptr(key))
69 
70 #define pset_new_ptr(slots) new_pset(pset_default_ptr_cmp, slots)
71 
72 #define pset_new_ptr_default() pset_new_ptr(64)
73 
75 typedef struct {
76  unsigned hash;
77  void *dptr;
78 } pset_entry;
79 
89 typedef int (*pset_cmp_fun) (const void *elt, const void *key);
90 
101 FIRM_API pset *new_pset(pset_cmp_fun func, size_t slots);
102 
111 FIRM_API void del_pset(pset *pset);
112 
118 FIRM_API size_t pset_count(pset *pset);
119 
130 FIRM_API void *pset_find(pset *pset, const void *key, unsigned hash);
131 
147 FIRM_API void *pset_insert(pset *pset, const void *key, unsigned hash);
148 
163 FIRM_API pset_entry *pset_hinsert(pset *pset, const void *key, unsigned hash);
164 
181 FIRM_API void *pset_remove(pset *pset, const void *key, unsigned hash);
182 
190 FIRM_API void *pset_first(pset *pset);
191 
202 #define pset_first(type, pset) ((type*)pset_first((pset)))
203 
212 FIRM_API void *pset_next(pset *pset);
213 
225 #define pset_next(type, pset) ((type*)pset_next((pset)))
226 
235 
243 #define foreach_pset(pset, type, entry) for (type *entry = pset_first(type, pset); entry; entry = pset_next(type, pset))
244 
252 FIRM_API void pset_insert_pset_ptr(pset *target, pset *src);
253 
256 #define new_pset(cmp, slots) ((new_pset) ((cmp), (slots)))
257 #define pset_find(pset, key, hash) \
258  _pset_search ((pset), (key), (hash), _pset_find)
259 #define pset_insert(pset, key, hash) \
260  _pset_search ((pset), (key), (hash), _pset_insert)
261 #define pset_hinsert(pset, key, hash) \
262  ((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert))
263 
264 typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
265 
266 FIRM_API void *_pset_search(pset *, const void *, unsigned, _pset_action);
267 
272 #include "../end.h"
273 
274 #endif