]>
Commit | Line | Data |
---|---|---|
0e2cd867 | 1 | /* |
186477c1 | 2 | * $Id: hash.h,v 1.4 2000/10/31 23:48:08 wessels Exp $ |
0e2cd867 | 3 | */ |
4 | ||
f52a7d75 | 5 | typedef void HASHFREE(void *); |
6 | typedef int HASHCMP(const void *, const void *); | |
7 | typedef unsigned int HASHHASH(const void *, unsigned int); | |
8 | typedef struct _hash_link hash_link; | |
9 | typedef struct _hash_table hash_table; | |
10 | ||
11 | struct _hash_link { | |
186477c1 | 12 | void *key; |
f52a7d75 | 13 | hash_link *next; |
14 | }; | |
15 | ||
16 | struct _hash_table { | |
17 | hash_link **buckets; | |
18 | HASHCMP *cmp; | |
19 | HASHHASH *hash; | |
20 | unsigned int size; | |
21 | unsigned int current_slot; | |
22 | hash_link *next; | |
23 | int count; | |
24 | }; | |
25 | ||
26 | extern hash_table *hash_create(HASHCMP *, int, HASHHASH *); | |
27 | extern void hash_join(hash_table *, hash_link *); | |
28 | extern void hash_remove_link(hash_table *, hash_link *); | |
29 | extern int hashPrime(int n); | |
30 | extern void *hash_lookup(hash_table *, const void *); | |
31 | extern void hash_first(hash_table *); | |
32 | extern void *hash_next(hash_table *); | |
2c4f7ab2 | 33 | extern void hash_last(hash_table *); |
f52a7d75 | 34 | extern hash_link *hash_get_bucket(hash_table *, unsigned int); |
35 | extern void hashFreeMemory(hash_table *); | |
36 | extern void hashFreeItems(hash_table *, HASHFREE *); | |
37 | extern HASHHASH hash_string; | |
38 | extern HASHHASH hash4; | |
186477c1 | 39 | extern const char *hashKeyStr(hash_link *); |
f52a7d75 | 40 | |
41 | /* | |
42 | * Here are some good prime number choices. It's important not to | |
43 | * choose a prime number that is too close to exact powers of 2. | |
44 | * | |
45 | * HASH_SIZE 103 // prime number < 128 | |
46 | * HASH_SIZE 229 // prime number < 256 | |
47 | * HASH_SIZE 467 // prime number < 512 | |
48 | * HASH_SIZE 977 // prime number < 1024 | |
49 | * HASH_SIZE 1979 // prime number < 2048 | |
50 | * HASH_SIZE 4019 // prime number < 4096 | |
51 | * HASH_SIZE 6037 // prime number < 6144 | |
52 | * HASH_SIZE 7951 // prime number < 8192 | |
53 | * HASH_SIZE 12149 // prime number < 12288 | |
54 | * HASH_SIZE 16231 // prime number < 16384 | |
55 | * HASH_SIZE 33493 // prime number < 32768 | |
56 | * HASH_SIZE 65357 // prime number < 65536 | |
57 | */ | |
186477c1 | 58 | #define DEFAULT_HASH_SIZE 7951 /* prime number < 8192 */ |