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