698d7536b6b5b82c366f3e3e2d40fa789f2fd103
[libfirm] / ir / adt / pset.h
1 /* Declarations for pset.
2    Copyright (C) 1995, 1996 Markus Armbruster */
3
4 /* $Id$ */
5
6 #ifndef _PSET_H
7 #define _PSET_H
8
9 #include <stddef.h>
10
11 typedef struct pset pset;
12
13 typedef struct {
14   unsigned hash;
15   void *dptr;
16 } pset_entry;
17
18
19 typedef int (*pset_cmp_fun) (const void *, const void *);
20
21 /* Makes new hash table. Needs function to compare two nodes to
22    resolve hash value collision and the size. */
23 pset *new_pset (pset_cmp_fun, int slots);
24 /* Deletes hash table */
25 void del_pset (pset *);
26
27 /* Returns the pointer associated with pointer key.  Hash is
28    the hash value computed from key.  Returns Null if key not
29    in hash table.  */
30 void *pset_find (pset *, const void *key, unsigned hash);
31 void *pset_insert (pset *, const void *key, unsigned hash);
32 pset_entry *pset_hinsert (pset *, const void *key, unsigned hash);
33 void *pset_remove (pset *, const void *key, unsigned hash);
34
35 void *pset_first (pset *);
36 void *pset_next (pset *);
37 void pset_break (pset *);
38
39 #define new_pset(cmp, slots) (PSET_TRACE (new_pset) ((cmp), (slots)))
40 #define pset_find(pset, key, hash) \
41   _pset_search ((pset), (key), (hash), _pset_find)
42 #define pset_insert(pset, key, hash) \
43   _pset_search ((pset), (key), (hash), _pset_insert)
44 #define pset_hinsert(pset, key, hash) \
45   ((pset_entry *)_pset_search ((pset), (key), (hash), _pset_hinsert))
46
47 #ifdef STATS
48 void pset_stats (pset *);
49 #else
50 # define pset_stats(s) ((void)0)
51 #endif
52
53 #ifdef DEBUG
54 void pset_describe (pset *);
55 #endif
56
57 /* @@@ NYI */
58 #define PSET_VRFY(pset) (void)0
59
60
61 /* Private */
62
63 typedef enum { _pset_find, _pset_insert, _pset_hinsert } _pset_action;
64
65 void *_pset_search (pset *, const void *, unsigned, _pset_action);
66
67 #if defined(DEBUG) && defined(HAVE_GNU_MALLOC)
68 extern const char *pset_tag;
69 # ifdef PSET_ID
70 #   define PSET_TRACE pset_tag = SET_ID,
71 # else
72 #   define PSET_TRACE pset_tag = __FILE__,
73 # endif
74 #else /* !(DEBUG && HAVE_GNU_MALLOC) */
75 #   define PSET_TRACE
76 #endif /* !(DEBUG && HAVE_GNU_MALLOC) */
77
78 #endif