3 * File name: ir/adt/pset.h
4 * Purpose: Declarations for pset.
5 * Author: Markus Armbruster
7 * Created: 1999 by getting from fiasco
9 * Copyright: (c) 1995, 1996 Markus Armbruster
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
19 * The abstract type of a pset (Set of pointers).
21 * This kind of sets stores only pointer to elements, the elements itself
22 * must be stored somewere else.
26 typedef struct pset pset;
28 /** The entry of a pset, representing an element pointer in the set and it's meta-information */
35 * The type of a set compare function.
37 * @param elt pointer to an element
38 * @param key pointer to another element
41 * 0 if the elements are identically, non-zero else
43 typedef int (*pset_cmp_fun) (const void *elt, const void *key);
48 * @param func the compare function of this pset
49 * @param slots number of slots
54 pset *new_pset (pset_cmp_fun func, int slots);
60 * This does NOT delete the elements of this pset, just it's pointers!
62 void del_pset (pset *pset);
65 * Searches an element pointer in a pset.
67 * @param pset the pset to search in
68 * @param key the element to is searched
69 * @param hash the hash value of key
72 * the pointer of the found element in the pset of NULL if it was not found
74 void *pset_find (pset *pset, const void *key, unsigned hash);
77 * Inserts an element pointer into a pset.
79 * @param pset the pset to insert in
80 * @param key a pointer to the element to be inserted
81 * @param hash the hash-value of the element
83 * @return a pointer to the inserted element
86 * It is not possible to insert on element more than once. If a element
87 * that should be inserted is already in the set, this functions does
88 * nothing but returning its set_entry.
91 void *pset_insert (pset *pset, const void *key, unsigned hash);
94 * Inserts an element pointer into a pset and returns its pset_entry.
96 * @param pset the pset to insert in
97 * @param key a pointer to the element to be inserted
98 * @param hash the hash-value of the element
100 * @return a pointer to the pset_entry of the inserted element
103 * It is not possible to insert on element more than once. If a element
104 * that should be inserted is already in the pset, this functions does
105 * nothing but returning its pset_entry.
107 pset_entry *pset_hinsert (pset *pset, const void *key, unsigned hash);
110 * Removes an element from a pset.
112 * @param pset the pset to insert in
113 * @param key a pointer to the element to be inserted
114 * @param hash the hash-value of the element
117 * the pointer to the removed element
120 * The current implementation did not allow to remove non-existing elements
122 void *pset_remove (pset *pset, const void *key, unsigned hash);
124 /** returns the first element of a pset */
125 void *pset_first (pset *pset);
127 /** returns the next element of a pset */
128 void *pset_next (pset *pset);
130 /** Breaks the iteration of a set. Must be called before the next pset_first() call */
131 void pset_break (pset *pset);
133 #define new_pset(cmp, slots) (PSET_TRACE (new_pset) ((cmp), (slots)))
134 #define pset_find(pset, key, hash) \
135 _pset_search ((pset), (key), (hash), _pset_find)
136 #define pset_insert(pset, key, hash) \
137 _pset_search ((pset), (key), (hash), _pset_insert)
138 #define pset_hinsert(pset, key, hash) \
139 ((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert))
142 void pset_stats (pset *);
144 # define pset_stats(s) ((void)0)
148 void pset_describe (pset *);
152 #define PSET_VRFY(pset) (void)0
157 typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
159 void *_pset_search (pset *, const void *, unsigned, _pset_action);
161 #if defined(DEBUG) && defined(HAVE_GNU_MALLOC)
162 extern const char *pset_tag;
164 # define PSET_TRACE pset_tag = SET_ID,
166 # define PSET_TRACE pset_tag = __FILE__,
168 #else /* !(DEBUG && HAVE_GNU_MALLOC) */
170 #endif /* !(DEBUG && HAVE_GNU_MALLOC) */