add license prefix
[cparser] / adt / hashset.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20
21 /**
22  * @file
23  * @date    16.03.2007
24  * @brief   Generic hashset functions
25  * @author  Matthias Braun
26  * @version $Id$
27  */
28
29 /* You have to specialize this header by defining HashSet, HashSetIterator and
30  * ValueType */
31 #ifdef HashSet
32
33 #include <stdlib.h>
34
35 #ifdef DO_REHASH
36 #define HashSetEntry ValueType
37 #else
38 typedef struct HashSetEntry {
39         ValueType data;
40         unsigned hash;
41 } HashSetEntry;
42 #endif
43
44 #ifndef NO_TYPEDEFS
45 typedef struct HashSet         HashSet;
46 typedef struct HashSetIterator HashSetIterator;
47 #endif
48
49 struct HashSet {
50         HashSetEntry *entries;
51         size_t num_buckets;
52         size_t enlarge_threshold;
53         size_t shrink_threshold;
54         size_t num_elements;
55         size_t num_deleted;
56         int consider_shrink;
57 #ifndef NDEBUG
58         unsigned entries_version;
59 #endif
60 #ifdef ADDITIONAL_DATA
61         ADDITIONAL_DATA;
62 #endif
63 };
64
65 struct HashSetIterator {
66         HashSetEntry *current_bucket;
67         HashSetEntry *end;
68 #ifndef NDEBUG
69         const HashSet *set;
70         unsigned entries_version;
71 #endif
72 };
73
74 #ifdef DO_REHASH
75 #undef HashSetEntry
76 #endif
77
78 #endif