libFirm
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
pset.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5 
12 #ifndef FIRM_ADT_PSET_H
13 #define FIRM_ADT_PSET_H
14 
15 #include <stddef.h>
16 
17 #include "hashptr.h"
18 
19 #include "../begin.h"
20 
35 FIRM_API int pset_default_ptr_cmp(void const *x, void const *y);
36 
45 typedef struct pset pset;
46 
48 #define pset_insert_ptr(set,key) pset_insert(set, key, hash_ptr(key))
49 
50 #define pset_hinsert_ptr(set,key) pset_hinsert(set, key, hash_ptr(key))
51 
52 #define pset_remove_ptr(set,key) pset_remove(set, key, hash_ptr(key))
53 
54 #define pset_find_ptr(set,key) pset_find(set, key, hash_ptr(key))
55 
56 #define pset_new_ptr(slots) new_pset(pset_default_ptr_cmp, slots)
57 
58 #define pset_new_ptr_default() pset_new_ptr(64)
59 
62 typedef struct {
63  unsigned hash;
64  void *dptr;
65 } pset_entry;
66 
76 typedef int (*pset_cmp_fun) (void const *elt, void const *key);
77 
86 FIRM_API pset *new_pset(pset_cmp_fun func, size_t slots);
87 
96 FIRM_API void del_pset(pset *pset);
97 
103 FIRM_API size_t pset_count(pset const *pset);
104 
115 FIRM_API void *pset_find(pset *pset, void const *key, unsigned hash);
116 
131 FIRM_API void *pset_insert(pset *pset, void const *key, unsigned hash);
132 
147 FIRM_API pset_entry *pset_hinsert(pset *pset, void const *key, unsigned hash);
148 
165 FIRM_API void *pset_remove(pset *pset, void const *key, unsigned hash);
166 
174 FIRM_API void *pset_first(pset *pset);
175 
186 #define pset_first(type, pset) ((type*)pset_first((pset)))
187 
196 FIRM_API void *pset_next(pset *pset);
197 
209 #define pset_next(type, pset) ((type*)pset_next((pset)))
210 
218 FIRM_API void pset_break(pset *pset);
219 
227 #define foreach_pset(pset, type, entry) for (type *entry = pset_first(type, pset); entry; entry = pset_next(type, pset))
228 
236 FIRM_API void pset_insert_pset_ptr(pset *target, pset *src);
237 
240 #define new_pset(cmp, slots) ((new_pset) ((cmp), (slots)))
241 #define pset_find(pset, key, hash) \
242  _pset_search ((pset), (key), (hash), _pset_find)
243 #define pset_insert(pset, key, hash) \
244  _pset_search ((pset), (key), (hash), _pset_insert)
245 #define pset_hinsert(pset, key, hash) \
246  ((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert))
247 
248 typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
249 
250 FIRM_API void *_pset_search(pset *set, void const *key, unsigned hash,
251  _pset_action action);
252 
257 #include "../end.h"
258 
259 #endif
unsigned hash
hash value of element
Definition: pset.h:63
void * pset_insert(pset *pset, void const *key, unsigned hash)
Inserts an element pointer into a pset.
void * pset_remove(pset *pset, void const *key, unsigned hash)
Removes an element from a pset.
int pset_default_ptr_cmp(void const *x, void const *y)
The default comparison function for pointers.
void * dptr
pointer to element data
Definition: pset.h:64
void pset_break(pset *pset)
Breaks the iteration of a set.
pset * new_pset(pset_cmp_fun func, size_t slots)
Creates a new pset.
void pset_insert_pset_ptr(pset *target, pset *src)
Inserts all elements of the pointer set src into the set target (union).
pset_entry * pset_hinsert(pset *pset, void const *key, unsigned hash)
Inserts an element pointer into a pset and returns its pset_entry.
struct set set
The abstract type of a set.
Definition: set.h:34
void * pset_find(pset *pset, void const *key, unsigned hash)
Searches an element pointer in a pset.
struct pset pset
The abstract type of a pset (Set of pointers).
Definition: pset.h:45
int(* pset_cmp_fun)(void const *elt, void const *key)
The type of a set compare function.
Definition: pset.h:76
#define pset_next(type, pset)
Returns the next element of a pset.
Definition: pset.h:209
The entry of a pset, representing an element pointer in the set and its meta-information.
Definition: pset.h:62
size_t pset_count(pset const *pset)
Returns the number of elements in a pset.
void del_pset(pset *pset)
Deletes a pset.
#define pset_first(type, pset)
Returns the first element of a pset.
Definition: pset.h:186