00001 // 00002 // UCSD p-System cross compiler 00003 // Copyright (C) 2006 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or (at 00008 // you option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00018 // USA 00019 // 00020 00021 #ifndef LIB_SYMTAB_H 00022 #define LIB_SYMTAB_H 00023 00024 #include <lib/rcstring.h> 00025 #include <lib/rcstring/list.h> 00026 00032 class symtab_t 00033 { 00034 public: 00039 ~symtab_t(); 00040 00049 symtab_t(int suggested_size = 5); 00050 00055 size_t size() const { return hash_load; } 00056 00061 bool empty() const { return (hash_load == 0); } 00062 00070 void clear(void); 00071 00086 void *query(const rcstring &key) const; 00087 00103 rcstring query_fuzzy(const rcstring &key, double &best) const; 00104 00121 void assign(const rcstring &key, void *value); 00122 00138 void assign_push(const rcstring &key, void *value); 00139 00152 void remove(const rcstring &key); 00153 00167 void dump(const char *caption) const; 00168 00183 void keys(rcstring_list &result) const; 00184 00185 typedef void (*reaper_t)(void *); 00186 00192 void set_reap(reaper_t func) { reap = func; } 00193 00198 bool valid() const; 00199 00200 private: 00215 void split(void); 00216 00220 reaper_t reap; 00221 00222 struct row_t 00223 { 00224 rcstring key; 00225 void *data; 00226 row_t *overflow; 00227 row_t(const rcstring &arg) : key(arg), data(0), overflow(0) { } 00228 }; 00229 00235 row_t **hash_table; 00236 00237 typedef rcstring::hash_t hash_t; 00238 00243 hash_t hash_modulus; 00244 00251 hash_t hash_mask; 00252 00257 rcstring::hash_t hash_load; 00258 00262 symtab_t(const symtab_t &); 00263 00267 symtab_t &operator=(const symtab_t &); 00268 00269 friend class symtab_iterator_t; 00270 }; 00271 00272 #endif // LIB_SYMTAB_H
1.5.1