Initial import of c parser
[cparser] / adt / hashset.h
1 /**
2  * @file
3  * @date    16.03.2007
4  * @brief   Generic hashset functions
5  * @author  Matthias Braun
6  * @version $Id$
7  */
8
9 /* You have to specialize this header by defining HashSet, HashSetIterator and
10  * ValueType */
11 #ifdef HashSet
12
13 #include <stdlib.h>
14
15 #ifdef DO_REHASH
16 #define HashSetEntry ValueType
17 #else
18 typedef struct HashSetEntry {
19         ValueType data;
20         unsigned hash;
21 } HashSetEntry;
22 #endif
23
24 #ifndef NO_TYPEDEFS
25 typedef struct HashSet         HashSet;
26 typedef struct HashSetIterator HashSetIterator;
27 #endif
28
29 struct HashSet {
30         HashSetEntry *entries;
31         size_t num_buckets;
32         size_t enlarge_threshold;
33         size_t shrink_threshold;
34         size_t num_elements;
35         size_t num_deleted;
36         int consider_shrink;
37 #ifndef NDEBUG
38         unsigned entries_version;
39 #endif
40 #ifdef ADDITIONAL_DATA
41         ADDITIONAL_DATA;
42 #endif
43 };
44
45 struct HashSetIterator {
46         HashSetEntry *current_bucket;
47         HashSetEntry *end;
48 #ifndef NDEBUG
49         const HashSet *set;
50         unsigned entries_version;
51 #endif
52 };
53
54 #ifdef DO_REHASH
55 #undef HashSetEntry
56 #endif
57
58 #endif