494686c853fa9b93ac4c3c4cbc55cbd722cccf48
[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 /* Makes new hash table. Needs function to compare two nodes to
20    resolve hash value collision and the size. */
21 pset *new_pset (pset_cmp_fun, int slots);
22 /* Deletes hash table */
23 void del_pset (pset *);
24
25 /* Returns the pointer associated with pointer key.  Hash is
26    the hash value computed from key.  Returns Null if key not
27    in hash table.  */
28 void *pset_find (pset *, const void *key, unsigned hash);
29 void *pset_insert (pset *, const void *key, unsigned hash);
30 pset_entry *pset_hinsert (pset *, const void *key, unsigned hash);
31 void *pset_remove (pset *, const void *key, unsigned hash);
32
33 void *pset_first (pset *);
34 void *pset_next (pset *);
35 void pset_break (pset *);
36
37 #define new_pset(cmp, slots) (PSET_TRACE (new_pset) ((cmp), (slots)))
38 #define pset_find(pset, key, hash) \
39   _pset_search ((pset), (key), (hash), _pset_find)
40 #define pset_insert(pset, key, hash) \
41   _pset_search ((pset), (key), (hash), _pset_insert)
42 #define pset_hinsert(pset, key, hash) \
43   ((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert))
44
45 #ifdef STATS
46 void pset_stats (pset *);
47 #else
48 # define pset_stats(s) ((void)0)
49 #endif
50
51 #ifdef DEBUG
52 void pset_describe (pset *);
53 #endif
54
55 /* @@@ NYI */
56 #define PSET_VRFY(pset) (void)0
57
58
59 /* Private */
60
61 typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
62
63 void *_pset_search (pset *, const void *, unsigned, _pset_action);
64
65 #if defined(DEBUG) && defined(HAVE_GNU_MALLOC)
66 extern const char *pset_tag;
67 # ifdef PSET_ID
68 #   define PSET_TRACE pset_tag = SET_ID,
69 # else
70 #   define PSET_TRACE pset_tag = __FILE__,
71 # endif
72 #else /* !(DEBUG && HAVE_GNU_MALLOC) */
73 #   define PSET_TRACE
74 #endif /* !(DEBUG && HAVE_GNU_MALLOC) */
75
76 #endif