ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/shstr.h
Revision: 1.3
Committed: Tue Aug 29 08:01:36 2006 UTC (17 years, 9 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -2 lines
Log Message:
expand initial tabs to spaces

File Contents

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