1 /* Declarations for pset.
2 Copyright (C) 1995, 1996 Markus Armbruster */
9 * Declarations for pset.
18 * The abstract type of a pset (Set of pointers).
20 * This kind of sets stores only pointer to elements, the elements itself
21 * must be stored somewere else.
25 typedef struct pset pset;
27 /** The entry of a pset, representing an element pointer in the set and it's meta-information */
34 * The type of a set compare function.
36 * @param elt pointer to an element
37 * @param key pointer to another element
40 * 0 if the elements are identically, non-zero else
42 typedef int (*pset_cmp_fun) (const void *elt, const void *key);
47 * @param func the compare function of this pset
48 * @param slots number of slots
53 pset *new_pset (pset_cmp_fun func, int slots);
59 * This does NOT delete the elements of this pset, just it's pointers!
61 void del_pset (pset *pset);
64 * Searches an element pointer in a pset.
66 * @param pset the pset to search in
67 * @param key the element to is searched
68 * @param hash the hash value of key
71 * the pointer of the found element in the pset of NULL if it was not found
73 void *pset_find (pset *pset, const void *key, unsigned hash);
76 * Inserts an element pointer into a pset.
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
82 * @return a pointer to the inserted element
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.
90 void *pset_insert (pset *pset, const void *key, unsigned hash);
93 * Inserts an element pointer into a pset and returns its pset_entry.
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
99 * @return a pointer to the pset_entry of the inserted element
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.
106 pset_entry *pset_hinsert (pset *pset, const void *key, unsigned hash);
109 * Removes an element from a pset.
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
116 * the pointer to the removed element
119 * The current implementation did not allow to remove non-existing elements
121 void *pset_remove (pset *pset, const void *key, unsigned hash);
123 /** returns the first element of a pset */
124 void *pset_first (pset *pset);
126 /** returns the next element of a pset */
127 void *pset_next (pset *pset);
129 /** Breaks the iteration of a set. Must be called before the next pset_first() call */
130 void pset_break (pset *pset);
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))
141 void pset_stats (pset *);
143 # define pset_stats(s) ((void)0)
147 void pset_describe (pset *);
151 #define PSET_VRFY(pset) (void)0
156 typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
158 void *_pset_search (pset *, const void *, unsigned, _pset_action);
160 #if defined(DEBUG) && defined(HAVE_GNU_MALLOC)
161 extern const char *pset_tag;
163 # define PSET_TRACE pset_tag = SET_ID,
165 # define PSET_TRACE pset_tag = __FILE__,
167 #else /* !(DEBUG && HAVE_GNU_MALLOC) */
169 #endif /* !(DEBUG && HAVE_GNU_MALLOC) */