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