1a194faf8Srie /* 2a194faf8Srie * CDDL HEADER START 3a194faf8Srie * 4a194faf8Srie * The contents of this file are subject to the terms of the 5a194faf8Srie * Common Development and Distribution License (the "License"). 6a194faf8Srie * You may not use this file except in compliance with the License. 7a194faf8Srie * 8a194faf8Srie * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9a194faf8Srie * or http://www.opensolaris.org/os/licensing. 10a194faf8Srie * See the License for the specific language governing permissions 11a194faf8Srie * and limitations under the License. 12a194faf8Srie * 13a194faf8Srie * When distributing Covered Code, include this CDDL HEADER in each 14a194faf8Srie * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15a194faf8Srie * If applicable, add the following below this CDDL HEADER, with the 16a194faf8Srie * fields enclosed by brackets "[]" replaced with your own identifying 17a194faf8Srie * information: Portions Copyright [yyyy] [name of copyright owner] 18a194faf8Srie * 19a194faf8Srie * CDDL HEADER END 20a194faf8Srie */ 21a194faf8Srie /* 22*cce0e03bSab196087 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23a194faf8Srie * Use is subject to license terms. 24a194faf8Srie */ 25a194faf8Srie 26a194faf8Srie #ifndef __STRING_TABLE_DOT_H 27a194faf8Srie #define __STRING_TABLE_DOT_H 28a194faf8Srie 29a194faf8Srie #include <sys/types.h> 30a194faf8Srie #include <sys/avl.h> 31a194faf8Srie #include <string_table.h> 32a194faf8Srie 33a194faf8Srie #ifdef __cplusplus 34a194faf8Srie extern "C" { 35a194faf8Srie #endif 36a194faf8Srie 37a194faf8Srie /* 38a194faf8Srie * A string is represented in a string table using two values: length, and 39a194faf8Srie * value. Grouping all the strings of a given length together allows for 40a194faf8Srie * efficient matching of tail strings, as each input string value is hashed. 41a194faf8Srie * Each string table uses a 2-level AVL tree of AVL trees to represent this 42a194faf8Srie * organization. 43a194faf8Srie * 44a194faf8Srie * The outer (main) AVL tree contains LenNode structures. The search key for 45a194faf8Srie * nodes on this main tree is the string length. Each such node represents 46a194faf8Srie * all strings of a given length, and all strings of that length are found 47a194faf8Srie * within. 48a194faf8Srie * 49a194faf8Srie * The strings within each LenNode are maintained using a secondary AVL tree 50a194faf8Srie * of StrNode structures. The search key for this inner tree is the string 51a194faf8Srie * itself. The strings are maintained in lexical order. 52a194faf8Srie */ 53a194faf8Srie typedef struct { 54a194faf8Srie avl_node_t sn_avlnode; /* AVL book-keeping */ 55a194faf8Srie const char *sn_str; /* string */ 56*cce0e03bSab196087 size_t sn_refcnt; /* reference count */ 57a194faf8Srie } StrNode; 58a194faf8Srie 59a194faf8Srie typedef struct { 60a194faf8Srie avl_node_t ln_avlnode; /* AVL book-keeping */ 61a194faf8Srie avl_tree_t *ln_strtree; /* AVL tree of associated strings */ 62*cce0e03bSab196087 size_t ln_strlen; /* length of associated strings */ 63a194faf8Srie } LenNode; 64a194faf8Srie 65a194faf8Srie /* 66a194faf8Srie * Define a master string data item. Other strings may be suffixes of this 67a194faf8Srie * string. The final string table will consist of the master string values, 68a194faf8Srie * laid end to end, with the other strings referencing their tails. 69a194faf8Srie */ 70a194faf8Srie typedef struct str_master Str_master; 71a194faf8Srie 72a194faf8Srie struct str_master { 73a194faf8Srie const char *sm_str; /* pointer to master string */ 74a194faf8Srie Str_master *sm_next; /* used for tracking master strings */ 75*cce0e03bSab196087 size_t sm_strlen; /* length of master string */ 76a194faf8Srie uint_t sm_hashval; /* hashval of master string */ 77*cce0e03bSab196087 size_t sm_stroff; /* offset into destination strtab */ 78a194faf8Srie }; 79a194faf8Srie 80a194faf8Srie /* 81a194faf8Srie * Define a hash data item. This item represents an individual string that has 82a194faf8Srie * been input into the String hash table. The string may either be a suffix of 83a194faf8Srie * another string, or a master string. 84a194faf8Srie */ 85a194faf8Srie typedef struct str_hash Str_hash; 86a194faf8Srie 87a194faf8Srie struct str_hash { 88*cce0e03bSab196087 size_t hi_strlen; /* string length */ 89*cce0e03bSab196087 size_t hi_refcnt; /* number of references to str */ 90a194faf8Srie uint_t hi_hashval; /* hash for string */ 91a194faf8Srie Str_master *hi_mstr; /* pointer to master string */ 92a194faf8Srie Str_hash *hi_next; /* next entry in hash bucket */ 93a194faf8Srie }; 94a194faf8Srie 95a194faf8Srie /* 96a194faf8Srie * Controlling data structure for a String Table. 97a194faf8Srie */ 98a194faf8Srie struct str_tbl { 99a194faf8Srie avl_tree_t *st_lentree; /* AVL tree of string lengths */ 100a194faf8Srie char *st_strbuf; /* string buffer */ 101a194faf8Srie Str_hash **st_hashbcks; /* hash buckets */ 102a194faf8Srie Str_master *st_mstrlist; /* list of all master strings */ 103*cce0e03bSab196087 size_t st_fullstrsize; /* uncompressed table size */ 104*cce0e03bSab196087 size_t st_nextoff; /* next available string */ 105*cce0e03bSab196087 size_t st_strsize; /* compressed size */ 106*cce0e03bSab196087 size_t st_strcnt; /* number of strings */ 107a194faf8Srie uint_t st_hbckcnt; /* number of buckets in */ 108a194faf8Srie /* hashlist */ 109a194faf8Srie uint_t st_flags; 110a194faf8Srie }; 111a194faf8Srie 112a194faf8Srie #define FLG_STTAB_COMPRESS 0x01 /* compressed string table */ 113a194faf8Srie #define FLG_STTAB_COOKED 0x02 /* offset has been assigned */ 114a194faf8Srie 115a194faf8Srie /* 116a194faf8Srie * Starting value for use with string hashing functions inside of string_table.c 117a194faf8Srie */ 118a194faf8Srie #define HASHSEED 5381 119a194faf8Srie 120a194faf8Srie #ifdef __cplusplus 121a194faf8Srie } 122a194faf8Srie #endif 123a194faf8Srie 124a194faf8Srie #endif /* __STRING_TABLE_DOT_H */ 125