1 |
/* The size of the shared strings hashtable. This must be smaller than |
2 |
* 32767, but 947 ought to be plenty enough. |
3 |
*/ |
4 |
#define TABLESIZE 4133 |
5 |
|
6 |
/* This specifies how many characters the hashing routine should look at. |
7 |
* You may actually save CPU by increasing this number if the typical string |
8 |
* is large. |
9 |
*/ |
10 |
#ifndef MAXSTRING |
11 |
#define MAXSTRING 20 |
12 |
#endif |
13 |
|
14 |
/* In the unlikely occurence that 16383 references to a string are too |
15 |
* few, you can modify the below type to something bigger. |
16 |
* (The top bit of "refcount" is used to signify that "u.array" points |
17 |
* at the array entry.) |
18 |
*/ |
19 |
#define REFCOUNT_TYPE int |
20 |
|
21 |
/* The offsetof macro is part of ANSI C, but many compilers lack it, for |
22 |
* example "gcc -ansi" |
23 |
*/ |
24 |
#if !defined (offsetof) |
25 |
#define offsetof(type, member) (int)&(((type *)0)->member) |
26 |
#endif |
27 |
|
28 |
/* SS(string) will return the address of the shared_string struct which |
29 |
* contains "string". |
30 |
*/ |
31 |
#define SS(x) ((shared_string *) ((x) - offsetof(shared_string, string))) |
32 |
|
33 |
#define SS_STATISTICS |
34 |
|
35 |
#define SS_DUMP_TABLE 1 |
36 |
#define SS_DUMP_TOTALS 2 |
37 |
|
38 |
#ifdef SS_STATISTICS |
39 |
static struct statistics { |
40 |
int calls; |
41 |
int hashed; |
42 |
int strcmps; |
43 |
int search; |
44 |
int linked; |
45 |
} add_stats, add_ref_stats, free_stats, find_stats, hash_stats; |
46 |
#define GATHER(n) (++n) |
47 |
#else /* !SS_STATISTICS */ |
48 |
#define GATHER(n) |
49 |
#endif /* SS_STATISTICS */ |
50 |
|
51 |
#define TOPBIT ((unsigned REFCOUNT_TYPE) 1 << (sizeof(REFCOUNT_TYPE) * CHAR_BIT - 1)) |
52 |
|
53 |
#define PADDING ((2 * sizeof(long) - sizeof(REFCOUNT_TYPE)) % sizeof(long)) + 1 |
54 |
|
55 |
typedef struct _shared_string { |
56 |
union { |
57 |
struct _shared_string **array; |
58 |
struct _shared_string *previous; |
59 |
} u; |
60 |
struct _shared_string *next; |
61 |
/* The top bit of "refcount" is used to signify that "u.array" points |
62 |
* at the array entry. |
63 |
*/ |
64 |
unsigned REFCOUNT_TYPE refcount; |
65 |
/* Padding will be unused memory, since we can't know how large |
66 |
* the padding when allocating memory. We assume here that |
67 |
* sizeof(long) is a good boundary. |
68 |
*/ |
69 |
char string[PADDING]; |
70 |
} shared_string; |