rev |
line source |
emellor@9159
|
1 /* Copyright (C) 2002, 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk> */
|
emellor@9159
|
2
|
emellor@9159
|
3 #ifndef __HASHTABLE_PRIVATE_CWC22_H__
|
emellor@9159
|
4 #define __HASHTABLE_PRIVATE_CWC22_H__
|
emellor@9159
|
5
|
emellor@9159
|
6 #include "hashtable.h"
|
emellor@9159
|
7
|
emellor@9159
|
8 /*****************************************************************************/
|
emellor@9159
|
9 struct entry
|
emellor@9159
|
10 {
|
emellor@9159
|
11 void *k, *v;
|
emellor@9159
|
12 unsigned int h;
|
emellor@9159
|
13 struct entry *next;
|
emellor@9159
|
14 };
|
emellor@9159
|
15
|
emellor@9159
|
16 struct hashtable {
|
emellor@9159
|
17 unsigned int tablelength;
|
emellor@9159
|
18 struct entry **table;
|
emellor@9159
|
19 unsigned int entrycount;
|
emellor@9159
|
20 unsigned int loadlimit;
|
emellor@9159
|
21 unsigned int primeindex;
|
emellor@9159
|
22 unsigned int (*hashfn) (void *k);
|
emellor@9159
|
23 int (*eqfn) (void *k1, void *k2);
|
emellor@9159
|
24 };
|
emellor@9159
|
25
|
emellor@9159
|
26 /*****************************************************************************/
|
emellor@9159
|
27 unsigned int
|
emellor@9159
|
28 hash(struct hashtable *h, void *k);
|
emellor@9159
|
29
|
emellor@9159
|
30 /*****************************************************************************/
|
emellor@9159
|
31 /* indexFor */
|
emellor@9159
|
32 static inline unsigned int
|
emellor@9159
|
33 indexFor(unsigned int tablelength, unsigned int hashvalue) {
|
emellor@9159
|
34 return (hashvalue % tablelength);
|
emellor@9159
|
35 };
|
emellor@9159
|
36
|
emellor@9159
|
37 /* Only works if tablelength == 2^N */
|
emellor@9159
|
38 /*static inline unsigned int
|
emellor@9159
|
39 indexFor(unsigned int tablelength, unsigned int hashvalue)
|
emellor@9159
|
40 {
|
emellor@9159
|
41 return (hashvalue & (tablelength - 1u));
|
emellor@9159
|
42 }
|
emellor@9159
|
43 */
|
emellor@9159
|
44
|
emellor@9159
|
45 /*****************************************************************************/
|
emellor@9159
|
46 #define freekey(X) free(X)
|
emellor@9159
|
47 /*define freekey(X) ; */
|
emellor@9159
|
48
|
emellor@9159
|
49
|
emellor@9159
|
50 /*****************************************************************************/
|
emellor@9159
|
51
|
emellor@9159
|
52 #endif /* __HASHTABLE_PRIVATE_CWC22_H__*/
|
emellor@9159
|
53
|
emellor@9159
|
54 /*
|
emellor@9159
|
55 * Copyright (c) 2002, Christopher Clark
|
emellor@9159
|
56 * All rights reserved.
|
emellor@9159
|
57 *
|
emellor@9159
|
58 * Redistribution and use in source and binary forms, with or without
|
emellor@9159
|
59 * modification, are permitted provided that the following conditions
|
emellor@9159
|
60 * are met:
|
emellor@9159
|
61 *
|
emellor@9159
|
62 * * Redistributions of source code must retain the above copyright
|
emellor@9159
|
63 * notice, this list of conditions and the following disclaimer.
|
emellor@9159
|
64 *
|
emellor@9159
|
65 * * Redistributions in binary form must reproduce the above copyright
|
emellor@9159
|
66 * notice, this list of conditions and the following disclaimer in the
|
emellor@9159
|
67 * documentation and/or other materials provided with the distribution.
|
emellor@9159
|
68 *
|
emellor@9159
|
69 * * Neither the name of the original author; nor the names of any contributors
|
emellor@9159
|
70 * may be used to endorse or promote products derived from this software
|
emellor@9159
|
71 * without specific prior written permission.
|
emellor@9159
|
72 *
|
emellor@9159
|
73 *
|
emellor@9159
|
74 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
emellor@9159
|
75 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
emellor@9159
|
76 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
emellor@9159
|
77 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
emellor@9159
|
78 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
emellor@9159
|
79 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
emellor@9159
|
80 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
emellor@9159
|
81 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
emellor@9159
|
82 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
emellor@9159
|
83 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
emellor@9159
|
84 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
emellor@9159
|
85 */
|