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