6aa7dcbe23b089af8318159065b25b35fd235514
[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 /** The type of a pset (Set of pointers) */
18 typedef struct pset pset;
19
20 /** a pset entry */
21 typedef struct {
22   unsigned hash;
23   void *dptr;
24 } pset_entry;
25
26 /** the type of a pset compare function */
27 typedef int (*pset_cmp_fun) (const void *, const void *);
28
29 /** Makes new hash table. Needs function to compare two nodes to
30    resolve hash value collision and the size. */
31 pset *new_pset (pset_cmp_fun, int slots);
32
33 /** Deletes hash table */
34 void del_pset (pset *);
35
36 /** Returns the pointer associated with pointer key.  Hash is
37    the hash value computed from key.  Returns Null if key not
38    in hash table.  */
39 void *pset_find (pset *, const void *key, unsigned hash);
40 void *pset_insert (pset *, const void *key, unsigned hash);
41 pset_entry *pset_hinsert (pset *, const void *key, unsigned hash);
42 void *pset_remove (pset *, const void *key, unsigned hash);
43
44 /** returns the first element of a pset */
45 void *pset_first (pset *);
46
47 /** returns the next element of a pset */
48 void *pset_next (pset *);
49
50 /** breaks the iteration of a set. Must be called before the next pset_first() call */
51 void pset_break (pset *);
52
53 #define new_pset(cmp, slots) (PSET_TRACE (new_pset) ((cmp), (slots)))
54 #define pset_find(pset, key, hash) \
55   _pset_search ((pset), (key), (hash), _pset_find)
56 #define pset_insert(pset, key, hash) \
57   _pset_search ((pset), (key), (hash), _pset_insert)
58 #define pset_hinsert(pset, key, hash) \
59   ((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert))
60
61 #ifdef STATS
62 void pset_stats (pset *);
63 #else
64 # define pset_stats(s) ((void)0)
65 #endif
66
67 #ifdef DEBUG
68 void pset_describe (pset *);
69 #endif
70
71 /* @@@ NYI */
72 #define PSET_VRFY(pset) (void)0
73
74
75 /* Private */
76
77 typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
78
79 void *_pset_search (pset *, const void *, unsigned, _pset_action);
80
81 #if defined(DEBUG) && defined(HAVE_GNU_MALLOC)
82 extern const char *pset_tag;
83 # ifdef PSET_ID
84 #   define PSET_TRACE pset_tag = SET_ID,
85 # else
86 #   define PSET_TRACE pset_tag = __FILE__,
87 # endif
88 #else /* !(DEBUG && HAVE_GNU_MALLOC) */
89 #   define PSET_TRACE
90 #endif /* !(DEBUG && HAVE_GNU_MALLOC) */
91
92 #endif