Initial revision
[libfirm] / ir / adt / pset.h
1 /* Declarations for pset.
2    Copyright (C) 1995, 1996 Markus Armbruster */
3
4 #ifndef _PSET_H
5 #define _PSET_H
6
7 #include <stddef.h>
8
9 typedef struct pset pset;
10
11 typedef struct {
12   unsigned hash;
13   void *dptr;
14 } pset_entry;
15
16
17 typedef int (*pset_cmp_fun) (const void *, const void *);
18
19 pset *new_pset (pset_cmp_fun, int slots);
20 void del_pset (pset *);
21
22 void *pset_find (pset *, const void *key, unsigned hash);
23 void *pset_insert (pset *, const void *key, unsigned hash);
24 pset_entry *pset_hinsert (pset *, const void *key, unsigned hash);
25 void *pset_remove (pset *, const void *key, unsigned hash);
26
27 void *pset_first (pset *);
28 void *pset_next (pset *);
29 void pset_break (pset *);
30
31 #define new_pset(cmp, slots) (PSET_TRACE (new_pset) ((cmp), (slots)))
32 #define pset_find(pset, key, hash) \
33   _pset_search ((pset), (key), (hash), _pset_find)
34 #define pset_insert(pset, key, hash) \
35   _pset_search ((pset), (key), (hash), _pset_insert)
36 #define pset_hinsert(pset, key, hash) \
37   ((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert))
38
39 #ifdef STATS
40 void pset_stats (pset *);
41 #else
42 # define pset_stats(s) ((void)0)
43 #endif
44
45 #ifdef DEBUG
46 void pset_describe (pset *);
47 #endif
48
49 /* @@@ NYI */
50 #define PSET_VRFY(pset) (void)0
51
52
53 /* Private */
54
55 typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
56
57 void *_pset_search (pset *, const void *, unsigned, _pset_action);
58
59 #if defined(DEBUG) && defined(HAVE_GNU_MALLOC)
60 extern const char *pset_tag;
61 # ifdef PSET_ID
62 #   define PSET_TRACE pset_tag = SET_ID,
63 # else
64 #   define PSET_TRACE pset_tag = __FILE__,
65 # endif
66 #else /* !(DEBUG && HAVE_GNU_MALLOC) */
67 #   define PSET_TRACE
68 #endif /* !(DEBUG && HAVE_GNU_MALLOC) */
69
70 #endif