xref: /titanic_50/usr/src/cmd/sgs/include/string_table.h (revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_STRING_TABLE_DOT_H
28 #define	_STRING_TABLE_DOT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include <sys/avl.h>
35 #include <sgs.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 typedef	struct str_hash		Str_hash;
42 typedef	struct str_tbl		Str_tbl;
43 typedef	struct str_master	Str_master;
44 
45 
46 /*
47  * The Stringlist is the list of 'input strings'
48  * associatied with the AVL nodes Stringelem.
49  */
50 typedef struct stringlist {
51 	const char		*sl_string;
52 	struct stringlist	*sl_next;
53 } Stringlist;
54 
55 /*
56  * Nodes for the initial AVL tree which contains all of
57  * the input strings.  The AVL tree is indexed off of
58  * the length of the strings.  This permits later traversal
59  * of all of the strings based off of their string length.
60  */
61 typedef struct {
62 	avl_node_t	se_avlnode;
63 	Stringlist	*se_strlist;
64 	uint_t		se_stlen;
65 } Stringelem;
66 
67 
68 /*
69  * Pointer to the Master string, other strings may be suffixes
70  * of this string.
71  */
72 struct str_master {
73 	const char	*sm_str;	/* pointer to master string */
74 	Str_master	*sm_next;	/* used for tracking master strings */
75 	uint_t		sm_stlen;	/* length of master string */
76 	uint_t		sm_hashval;	/* hashval of master string */
77 	uint_t		sm_stoff;	/* offset into destination strtab */
78 };
79 
80 
81 /*
82  * Represents a individual string that was input into
83  * the String hash table.  The string may either be a
84  * suffix of another string or a master string.
85  */
86 struct str_hash {
87 	uint_t		hi_stlen;	/* string length */
88 	uint_t		hi_refcnt;	/* # of references to str */
89 	uint_t		hi_hashval;	/* hash for string */
90 	Str_master	*hi_mstr;	/* pointer to master string */
91 	Str_hash	*hi_next;	/* next entry in hash bckt */
92 };
93 
94 /*
95  * Controlling data structure for a String Table
96  */
97 struct str_tbl {
98 	avl_tree_t	*st_strtree;		/* avl tree of initial strs */
99 	char		*st_strbuf;		/* string buffer */
100 	Str_hash	**st_hashbcks;		/* hash buckets */
101 	Str_master	*st_mstrlist;		/* list of all master strings */
102 	uint_t		st_fullstringsize;	/* uncompressed table size */
103 	uint_t		st_nextoff;		/* next available string */
104 	uint_t		st_stringsize;		/* compressed size */
105 	uint_t		st_stringcnt;		/* # of strings */
106 	uint_t		st_hbckcnt;		/* # of buckets in hashlist */
107 	uint_t		st_flags;
108 };
109 
110 #define	FLG_STTAB_COOKED	0x00000001	/* offset has been assigned */
111 #define	FLG_STTAB_COMPRESS	0x00000002	/* build compressed str tab */
112 
113 /*
114  * starting value for use with string hashing functions
115  * inside of string_table.c
116  */
117 #define	HASHSEED		5381
118 
119 /*
120  * Flags for st_new
121  */
122 #define	FLG_STNEW_COMPRESS	0x00000001	/* build compressed str tab */
123 
124 /*
125  * exported string_table.c functions
126  */
127 extern int		st_delstring(Str_tbl *, const char *);
128 extern void		st_destroy(Str_tbl *);
129 extern uint_t		st_getstrtab_sz(Str_tbl *);
130 extern const char	*st_getstrbuf(Str_tbl *);
131 extern int		st_insert(Str_tbl *, const char *);
132 extern int		st_setstrbuf(Str_tbl *, char *, uint_t);
133 extern int		st_setstring(Str_tbl *, const char *, uint_t *);
134 extern Str_tbl		*st_new(uint_t);
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /* _STRING_TABLE_DOT_H */
141