00001 /* 00002 * Copyright (c) 2007, Novell Inc. 00003 * 00004 * This program is licensed under the BSD license, read LICENSE.BSD 00005 * for further information 00006 */ 00007 #ifndef SATSOLVER_STRINGPOOL_H 00008 #define SATSOLVER_STRINGPOOL_H 00009 00010 #include "pooltypes.h" 00011 #include "hash.h" 00012 00013 #define STRID_NULL 0 00014 #define STRID_EMPTY 1 00015 00016 struct _Stringpool 00017 { 00018 Offset *strings; // table of offsets into stringspace, indexed by Id: Id -> Offset 00019 int nstrings; // number of unique strings in stringspace 00020 char *stringspace; // space for all unique strings: stringspace + Offset = string 00021 Offset sstrings; // next free pos in stringspace 00022 00023 Hashtable stringhashtbl; // hash table: (string ->) Hash -> Id 00024 Hashmask stringhashmask; // modulo value for hash table (size of table - 1) 00025 }; 00026 00027 void stringpool_init(Stringpool *ss, const char *strs[]); 00028 void stringpool_init_empty(Stringpool *ss); 00029 void stringpool_clone(Stringpool *ss, Stringpool *from); 00030 void stringpool_free(Stringpool *ss); 00031 void stringpool_freehash(Stringpool *ss); 00032 00033 Id stringpool_str2id(Stringpool *ss, const char *str, int create); 00034 Id stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create); 00035 00036 void stringpool_shrink(Stringpool *ss); 00037 00038 00039 static inline const char * 00040 stringpool_id2str(Stringpool *ss, Id id) 00041 { 00042 return ss->stringspace + ss->strings[id]; 00043 } 00044 00045 #endif