tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hashtable.h
Go to the documentation of this file.
1 /* =============================================================================
2  *
3  * hashtable.h
4  *
5  * =============================================================================
6  *
7  * Copyright (C) Stanford University, 2006. All Rights Reserved.
8  * Author: Chi Cao Minh
9  *
10  * =============================================================================
11  *
12  * Options:
13  *
14  * LIST_NO_DUPLICATES (default: allow duplicates)
15  *
16  * HASHTABLE_RESIZABLE (enable dynamically increasing number of buckets)
17  *
18  * HASHTABLE_SIZE_FIELD (size is explicitely stored in
19  * hashtable and not implicitly defined by the sizes of
20  * all bucket lists => more conflicts in case of parallel access)
21  *
22  * =============================================================================
23  *
24  * For the license of bayes/sort.h and bayes/sort.c, please see the header
25  * of the files.
26  *
27  * ------------------------------------------------------------------------
28  *
29  * For the license of kmeans, please see kmeans/LICENSE.kmeans
30  *
31  * ------------------------------------------------------------------------
32  *
33  * For the license of ssca2, please see ssca2/COPYRIGHT
34  *
35  * ------------------------------------------------------------------------
36  *
37  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
38  * header of the files.
39  *
40  * ------------------------------------------------------------------------
41  *
42  * For the license of lib/rbtree.h and lib/rbtree.c, please see
43  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
44  *
45  * ------------------------------------------------------------------------
46  *
47  * Unless otherwise noted, the following license applies to STAMP files:
48  *
49  * Copyright (c) 2007, Stanford University
50  * All rights reserved.
51  *
52  * Redistribution and use in source and binary forms, with or without
53  * modification, are permitted provided that the following conditions are
54  * met:
55  *
56  * * Redistributions of source code must retain the above copyright
57  * notice, this list of conditions and the following disclaimer.
58  *
59  * * Redistributions in binary form must reproduce the above copyright
60  * notice, this list of conditions and the following disclaimer in
61  * the documentation and/or other materials provided with the
62  * distribution.
63  *
64  * * Neither the name of Stanford University nor the names of its
65  * contributors may be used to endorse or promote products derived
66  * from this software without specific prior written permission.
67  *
68  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
69  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
71  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
72  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
73  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
74  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
75  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
76  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
77  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
78  * THE POSSIBILITY OF SUCH DAMAGE.
79  *
80  * =============================================================================
81  */
82 
83 
84 #ifndef HASHTABLE_H
85 #define HASHTABLE_H 1
86 
87 
88 #include "list.h"
89 #include "pair.h"
90 #include "tm.h"
91 #include "types.h"
92 #include "lehigh.h"
93 
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
98 
102 };
103 
104 typedef struct hashtable {
106  long numBucket;
107 #ifdef HASHTABLE_SIZE_FIELD
108  long size;
109 #endif
110  ulong_t (*hash)(const void*);
112 
115  /* comparePairs should return <0 if before, 0 if equal, >0 if after */
116 } hashtable_t;
117 
118 
119 typedef struct hashtable_iter {
120  long bucket;
123 
124 
125 /* =============================================================================
126  * hashtable_iter_reset
127  * =============================================================================
128  */
129 void
130 hashtable_iter_reset (hashtable_iter_t* itPtr, hashtable_t* hashtablePtr);
131 
132 
133 /* =============================================================================
134  * TMhashtable_iter_reset
135  * =============================================================================
136  */
137 void
139  hashtable_iter_t* itPtr, hashtable_t* hashtablePtr);
140 
141 
142 /* =============================================================================
143  * hashtable_iter_hasNext
144  * =============================================================================
145  */
146 bool_t
147 hashtable_iter_hasNext (hashtable_iter_t* itPtr, hashtable_t* hashtablePtr);
148 
149 
150 /* =============================================================================
151  * TMhashtable_iter_hasNext
152  * =============================================================================
153  */
154 bool_t
156  hashtable_iter_t* itPtr, hashtable_t* hashtablePtr);
157 
158 
159 /* =============================================================================
160  * hashtable_iter_next
161  * =============================================================================
162  */
163 void*
164 hashtable_iter_next (hashtable_iter_t* itPtr, hashtable_t* hashtablePtr);
165 
166 
167 /* =============================================================================
168  * TMhashtable_iter_next
169  * =============================================================================
170  */
171 void*
173  hashtable_iter_t* itPtr, hashtable_t* hashtablePtr);
174 
175 
176 /* =============================================================================
177  * hashtable_alloc
178  * -- Returns NULL on failure
179  * -- Negative values for resizeRatio or growthFactor select default values
180  * =============================================================================
181  */
183 hashtable_alloc (long initNumBucket,
184  ulong_t (*hash)(const void*),
185  comparator_t* comparePairs,
186  long resizeRatio,
187  long growthFactor);
188 
189 
190 /* =============================================================================
191  * TMhashtable_alloc
192  * -- Returns NULL on failure
193  * -- Negative values for resizeRatio or growthFactor select default values
194  * =============================================================================
195  */
198  long initNumBucket,
199  ulong_t (*hash)(const void*),
200  comparator_t* comparePairs,
201  long resizeRatio,
202  long growthFactor);
203 
204 
205 /* =============================================================================
206  * hashtable_free
207  * =============================================================================
208  */
209 void
210 hashtable_free (hashtable_t* hashtablePtr);
211 
212 
213 /* =============================================================================
214  * TMhashtable_free
215  * =============================================================================
216  */
217 void
218 TMhashtable_free (TM_ARGDECL hashtable_t* hashtablePtr);
219 
220 
221 /* =============================================================================
222  * hashtable_isEmpty
223  * =============================================================================
224  */
225 bool_t
226 hashtable_isEmpty (hashtable_t* hashtablePtr);
227 
228 
229 /* =============================================================================
230  * TMhashtable_isEmpty
231  * =============================================================================
232  */
233 bool_t
235 
236 
237 /* =============================================================================
238  * hashtable_getSize
239  * -- Returns number of elements in hash table
240  * =============================================================================
241  */
242 long
243 hashtable_getSize (hashtable_t* hashtablePtr);
244 
245 
246 /* =============================================================================
247  * TMhashtable_getSize
248  * -- Returns number of elements in hash table
249  * =============================================================================
250  */
251 long
253 
254 
255 /* =============================================================================
256  * hashtable_containsKey
257  * =============================================================================
258  */
259 bool_t
260 hashtable_containsKey (hashtable_t* hashtablePtr, void* keyPtr);
261 
262 
263 /* =============================================================================
264  * TMhashtable_containsKey
265  * =============================================================================
266  */
267 bool_t
268 TMhashtable_containsKey (TM_ARGDECL hashtable_t* hashtablePtr, void* keyPtr);
269 
270 
271 /* =============================================================================
272  * hashtable_find
273  * -- Returns NULL on failure, else pointer to data associated with key
274  * =============================================================================
275  */
276 void*
277 hashtable_find (hashtable_t* hashtablePtr, void* keyPtr);
278 
279 
280 /* =============================================================================
281  * TMhashtable_find
282  * -- Returns NULL on failure, else pointer to data associated with key
283  * =============================================================================
284  */
285 void*
286 TMhashtable_find (TM_ARGDECL hashtable_t* hashtablePtr, void* keyPtr);
287 
288 
289 /* =============================================================================
290  * hashtable_insert
291  * =============================================================================
292  */
293 bool_t
294 hashtable_insert (hashtable_t* hashtablePtr, void* keyPtr, void* dataPtr);
295 
296 
297 /* =============================================================================
298  * TMhashtable_insert
299  * =============================================================================
300  */
301 bool_t
303  hashtable_t* hashtablePtr, void* keyPtr, void* dataPtr);
304 
305 
306 /* =============================================================================
307  * hashtable_remove
308  * -- Returns TRUE if successful, else FALSE
309  * =============================================================================
310  */
311 bool_t
312 hashtable_remove (hashtable_t* hashtablePtr, void* keyPtr);
313 
314 
315 /* =============================================================================
316  * TMhashtable_remove
317  * -- Returns TRUE if successful, else FALSE
318  * =============================================================================
319  */
320 bool_t
321 TMhashtable_remove (TM_ARGDECL hashtable_t* hashtablePtr, void* keyPtr);
322 
323 
324 #define TMHASHTABLE_ITER_RESET(it, ht) TMhashtable_iter_reset(TM_ARG it, ht)
325 #define TMHASHTABLE_ITER_HASNEXT(it, ht) TMhashtable_iter_hasNext(TM_ARG it, ht)
326 #define TMHASHTABLE_ITER_NEXT(it, ht) TMhashtable_iter_next(TM_ARG it, ht)
327 #define TMHASHTABLE_ALLOC(i, h, c, r, g) TMhashtable_alloc(TM_ARG, i, h, c, r, g)
328 #define TMHASHTABLE_FREE(ht) TMhashtable_free(TM_ARG ht)
329 #define TMHASHTABLE_ISEMPTY(ht) TMhashtable_isEmpty(TM_ARG ht)
330 #define TMHASHTABLE_GETSIZE(ht) TMhashtable_getSize(TM_ARG ht)
331 #define TMHASHTABLE_FIND(ht, k) TMhashtable_find(TM_ARG ht, k)
332 #define TMHASHTABLE_INSERT(ht, k, d) TMhashtable_insert(TM_ARG ht, k, d)
333 #define TMHASHTABLE_REMOVE(ht) TMhashtable_remove(TM_ARG ht)
334 
335 
336 #ifdef __cplusplus
337 }
338 #endif
339 
340 
341 #endif /* HASHTABLE_H */
342 
343 
344 /* =============================================================================
345  *
346  * End of hashtable.h
347  *
348  * =============================================================================
349  */
bool_t hashtable_remove(hashtable_t *hashtablePtr, void *keyPtr)
Definition: hashtable.c:765
long numBucket
Definition: hashtable.h:106
long growthFactor
Definition: hashtable.h:114
void * TMhashtable_iter_next(TM_ARGDECL hashtable_iter_t *itPtr, hashtable_t *hashtablePtr)
Definition: hashtable.c:212
void hashtable_iter_reset(hashtable_iter_t *itPtr, hashtable_t *hashtablePtr)
Definition: hashtable.c:105
bool_t hashtable_containsKey(hashtable_t *hashtablePtr, void *keyPtr)
Definition: hashtable.c:546
void * TMhashtable_find(TM_ARGDECL hashtable_t *hashtablePtr, void *keyPtr)
Definition: hashtable.c:605
comparator_t * comparePairs
Definition: hashtable.h:111
bool_t TMhashtable_iter_hasNext(TM_ARGDECL hashtable_iter_t *itPtr, hashtable_t *hashtablePtr)
Definition: hashtable.c:155
Definition: hashtable.h:119
unsigned long ulong_t
Definition: types.h:88
Definition: hashtable.h:100
bool_t hashtable_iter_hasNext(hashtable_iter_t *itPtr, hashtable_t *hashtablePtr)
Definition: hashtable.c:130
long resizeRatio
Definition: hashtable.h:113
hashtable_t * TMhashtable_alloc(TM_ARGDECL long initNumBucket, ulong_t(*hash)(const void *), comparator_t *comparePairs, long resizeRatio, long growthFactor)
Definition: hashtable.c:356
void hashtable_free(hashtable_t *hashtablePtr)
Definition: hashtable.c:430
int bool_t
Definition: portable_defns.h:32
#define TM_ARGDECL
Definition: tm.h:532
void * hashtable_iter_next(hashtable_iter_t *itPtr, hashtable_t *hashtablePtr)
Definition: hashtable.c:181
struct hashtable_iter hashtable_iter_t
bool_t hashtable_isEmpty(hashtable_t *hashtablePtr)
Definition: hashtable.c:454
void * hashtable_find(hashtable_t *hashtablePtr, void *keyPtr)
Definition: hashtable.c:583
bool_t TMhashtable_remove(TM_ARGDECL hashtable_t *hashtablePtr, void *keyPtr)
Definition: hashtable.c:798
long TMhashtable_getSize(TM_ARGDECL hashtable_t *hashtablePtr)
Definition: hashtable.c:524
hashtable_config
Definition: hashtable.h:99
bool_t hashtable_insert(hashtable_t *hashtablePtr, void *keyPtr, void *dataPtr)
Definition: hashtable.c:663
void TMhashtable_iter_reset(TM_ARGDECL hashtable_iter_t *itPtr, hashtable_t *hashtablePtr)
Definition: hashtable.c:117
hashtable_t * hashtable_alloc(long initNumBucket, ulong_t(*hash)(const void *), comparator_t *comparePairs, long resizeRatio, long growthFactor)
Definition: hashtable.c:315
ulong_t(* hash)(const void *)
Definition: hashtable.h:110
bool_t TMhashtable_isEmpty(TM_ARGDECL hashtable_t *hashtablePtr)
Definition: hashtable.c:477
Definition: list.h:86
long bucket
Definition: hashtable.h:120
bool_t TMhashtable_insert(TM_ARGDECL hashtable_t *hashtablePtr, void *keyPtr, void *dataPtr)
Definition: hashtable.c:725
Definition: list.h:93
Definition: hashtable.h:101
Definition: lehigh.h:29
bool_t TMhashtable_containsKey(TM_ARGDECL hashtable_t *hashtablePtr, void *keyPtr)
Definition: hashtable.c:564
long hashtable_getSize(hashtable_t *hashtablePtr)
Definition: hashtable.c:501
void TMhashtable_free(TM_ARGDECL hashtable_t *hashtablePtr)
Definition: hashtable.c:442
list_iter_t it
Definition: hashtable.h:121
struct hashtable hashtable_t
list_t ** buckets
Definition: hashtable.h:105
Definition: hashtable.h:104