| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#ifndef SHSTR_H |
| 7 |
#define SHSTR_H |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#define TABLESIZE 4133 |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef MAXSTRING |
| 21 |
#define MAXSTRING 20 |
| 22 |
#endif |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#define REFCOUNT_TYPE int |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#if !defined(offsetof) |
| 37 |
#define offsetof(type, member) (int)&(((type *)0)->member) |
| 38 |
#endif |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#define SS(x) ((shared_string *) ((x)-offsetof(shared_string, string))) |
| 45 |
|
| 46 |
#define SS_DUMP_TABLE 1 |
| 47 |
#define SS_DUMP_TOTALS 2 |
| 48 |
|
| 49 |
#ifdef SS_STATISTICS |
| 50 |
|
| 51 |
static struct statistics { |
| 52 |
int calls; |
| 53 |
int hashed; |
| 54 |
int strcmps; |
| 55 |
int search; |
| 56 |
int linked; |
| 57 |
} add_stats, add_ref_stats, free_stats, find_stats, hash_stats; |
| 58 |
#define GATHER(n) (++n) |
| 59 |
#else |
| 60 |
#define GATHER(n) |
| 61 |
#endif |
| 62 |
|
| 63 |
#define TOPBIT ((unsigned REFCOUNT_TYPE)1<<(sizeof(REFCOUNT_TYPE)*CHAR_BIT-1)) |
| 64 |
|
| 65 |
#define PADDING ((2*sizeof(long)-sizeof(REFCOUNT_TYPE))%sizeof(long))+1 |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
typedef struct _shared_string { |
| 71 |
union { |
| 72 |
struct _shared_string **array; |
| 73 |
struct _shared_string *previous; |
| 74 |
} u; |
| 75 |
struct _shared_string *next; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
unsigned REFCOUNT_TYPE refcount; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
char string[PADDING]; |
| 85 |
} shared_string; |
| 86 |
|
| 87 |
#endif |