Typo fixed.
[libfirm] / ir / adt / pset.h
1 /* Declarations for pset.
2    Copyright (C) 1995, 1996 Markus Armbruster */
3
4 /* $Id$ */
5
6 /**
7  * @file pset.h
8  *
9  * Declarations for pset.
10  */
11
12 #ifndef _PSET_H
13 #define _PSET_H
14
15 #include <stddef.h>
16
17 /**
18  * The abstract type of a pset (Set of pointers).
19  *
20  * This kind of sets stores only pointer to elements, the elements itself
21  * must be stored somewere else.
22  *
23  * @see set
24  */
25 typedef struct pset pset;
26
27 /** The entry of a pset, representing an element pointer in the set and it's meta-information */
28 typedef struct {
29   unsigned hash;
30   void *dptr;
31 } pset_entry;
32
33 /**
34  * The type of a set compare function.
35  *
36  * @param elt   pointer to an element
37  * @param key   pointer to another element
38  *
39  * @return
40  *    0 if the elements are identically, non-zero else
41  */
42 typedef int (*pset_cmp_fun) (const void *elt, const void *key);
43
44 /**
45  * Creates a new pset.
46  *
47  * @param func    the compare function of this pset
48  * @param slots   number of slots
49  *
50  * @returns
51  *    created pset
52  */
53 pset *new_pset (pset_cmp_fun func, int slots);
54
55 /**
56  * Deletes a pset.
57  *
58  * @note
59  *    This does NOT delete the elements of this pset, just it's pointers!
60  */
61 void del_pset (pset *pset);
62
63 /**
64  * Searches an element pointer in a pset.
65  *
66  * @param pset  the pset to search in
67  * @param key   the element to is searched
68  * @param hash  the hash value of key
69  *
70  * @return
71  *    the pointer of the found element in the pset of NULL if it was not found
72  */
73 void *pset_find (pset *pset, const void *key, unsigned hash);
74
75 /**
76  * Inserts an element pointer into a pset.
77  *
78  * @param pset  the pset to insert in
79  * @param key   a pointer to the element to be inserted
80  * @param hash  the hash-value of the element
81  *
82  * @return a pointer to the inserted element
83  *
84  * @note
85  *    It is not possible to insert on element more than once. If a element
86  *    that should be inserted is already in the set, this functions does
87  *    nothing but returning its set_entry.
88
89  */
90 void *pset_insert (pset *pset, const void *key, unsigned hash);
91
92 /**
93  * Inserts an element pointer into a pset and returns its pset_entry.
94  *
95  * @param pset  the pset to insert in
96  * @param key   a pointer to the element to be inserted
97  * @param hash  the hash-value of the element
98  *
99  * @return a pointer to the pset_entry of the inserted element
100  *
101  * @note
102  *    It is not possible to insert on element more than once. If a element
103  *    that should be inserted is already in the pset, this functions does
104  *    nothing but returning its pset_entry.
105  */
106 pset_entry *pset_hinsert (pset *pset, const void *key, unsigned hash);
107
108 /**
109  * Removes an element from a pset.
110  *
111  * @param pset  the pset to insert in
112  * @param key   a pointer to the element to be inserted
113  * @param hash  the hash-value of the element
114  *
115  * @return
116  *    the pointer to the removed element
117  *
118  * @remark
119  *    The current implementation did not allow to remove non-existing elements
120  */
121 void *pset_remove (pset *pset, const void *key, unsigned hash);
122
123 /** returns the first element of a pset */
124 void *pset_first (pset *pset);
125
126 /** returns the next element of a pset */
127 void *pset_next (pset *pset);
128
129 /** Breaks the iteration of a set. Must be called before the next pset_first() call */
130 void pset_break (pset *pset);
131
132 #define new_pset(cmp, slots) (PSET_TRACE (new_pset) ((cmp), (slots)))
133 #define pset_find(pset, key, hash) \
134   _pset_search ((pset), (key), (hash), _pset_find)
135 #define pset_insert(pset, key, hash) \
136   _pset_search ((pset), (key), (hash), _pset_insert)
137 #define pset_hinsert(pset, key, hash) \
138   ((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert))
139
140 #ifdef STATS
141 void pset_stats (pset *);
142 #else
143 # define pset_stats(s) ((void)0)
144 #endif
145
146 #ifdef DEBUG
147 void pset_describe (pset *);
148 #endif
149
150 /* @@@ NYI */
151 #define PSET_VRFY(pset) (void)0
152
153
154 /* Private */
155
156 typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
157
158 void *_pset_search (pset *, const void *, unsigned, _pset_action);
159
160 #if defined(DEBUG) && defined(HAVE_GNU_MALLOC)
161 extern const char *pset_tag;
162 # ifdef PSET_ID
163 #   define PSET_TRACE pset_tag = SET_ID,
164 # else
165 #   define PSET_TRACE pset_tag = __FILE__,
166 # endif
167 #else /* !(DEBUG && HAVE_GNU_MALLOC) */
168 #   define PSET_TRACE
169 #endif /* !(DEBUG && HAVE_GNU_MALLOC) */
170
171 #endif