1 #ifndef SYMBOL_TABLE_CLASS
2 #define SYMBOL_TABLE_CLASS
28 template <
class contents>
class internal_symbol_indexer;
29 template <
class contents>
class internal_symbol_info;
30 template <
class contents>
class internal_symbol_list;
34 template <
class contents>
127 template <
class contents>
139 #ifdef DEBUG_SYMBOL_TABLE
141 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
148 template <
class contents>
167 template <
class contents>
176 template <
class contents>
178 :
public pointer_hash<internal_pointer_hider<contents> >
189 template <
class contents>
191 :
public string_hash<internal_symbol_info<contents> >
202 #undef static_class_name
203 #define static_class_name() "symbol_table"
205 template <
class contents>
211 template <
class contents>
214 (to_copy._symbol_list->estimated_elements())),
218 template <
class contents>
225 template <
class contents>
227 {
return _symbol_list->estimated_elements(); }
229 template <
class contents>
232 _symbol_list->rehash(estimated_elements);
233 _tracker->rehash(estimated_elements);
236 template <
class contents>
238 { rehash(new_elements); }
240 template <
class contents>
242 {
return _tracker->ids().elements(); }
244 template <
class contents>
248 if (
this == &to_copy)
return *
this;
250 for (
int i = 0; i < to_copy.
symbols(); i++) {
255 _symbol_list->add(info->
_name, new_info);
258 _tracker->add(new_info, new_track);
264 template <
class contents>
267 _symbol_list->reset();
271 template <
class contents>
274 bounds_return(index, 0, symbols() - 1, basis::bogonic<basis::astring>());
275 return get_index(index)->_name;
278 template <
class contents>
282 for (
int i = 0; i < symbols(); i++)
283 to_fill += get_index(i)->_name;
286 template <
class contents>
291 return _tracker->find(_tracker->ids()[index])->_held;
294 template <
class contents>
297 bounds_return(index, 0, symbols() - 1, basis::bogonic<contents>());
299 if (!found)
return basis::bogonic<contents>();
303 template <
class contents>
306 bounds_return(index, 0, symbols() - 1, basis::bogonic<contents>());
308 if (!found)
return basis::bogonic<contents>();
312 template <
class contents>
321 template <
class contents>
325 if (!entry)
return basis::common::NOT_FOUND;
327 for (
int i = 0; i < symbols(); i++) {
328 if (_tracker->ids()[i] == entry)
return i;
330 return basis::common::NOT_FOUND;
333 template <
class contents>
343 template <
class contents>
347 #ifdef DEBUG_SYMBOL_TABLE
348 FUNCDEF(
"sym_tab_finder_apply");
351 = (sym_tab_apply_data<contents> *)data_link;
352 #ifdef DEBUG_SYMBOL_TABLE
355 bool equals = package->_scf(key, package->_to_find);
357 package->_found = ¤t;
363 template <
class contents>
367 #ifdef DEBUG_SYMBOL_TABLE
370 if (!comparator)
return find(name);
371 #ifdef DEBUG_SYMBOL_TABLE
375 pack._to_find = name;
376 pack._scf = comparator;
382 template <
class contents>
391 _symbol_list->add(name, new_item);
394 _tracker->add(new_item, new_track);
395 return basis::common::IS_NEW;
399 return basis::common::EXISTING;
402 template <
class contents>
406 return whack(dead_name);
409 template <
class contents>
415 bool found_it = _symbol_list->zap(name);
417 _tracker->zap(sep_ind);
419 return found_it? basis::common::OKAY : basis::common::NOT_FOUND;
422 template <
class contents>
426 bounds_return(index, 0, symbols() - 1, basis::common::NOT_FOUND);
430 return basis::common::OKAY;
435 template <
class contents>
445 if (names_a != names_b)
return false;
447 for (
int i = 0; i < names_a.
elements(); i++) {
449 const contents *a_value = a.
find(current_key);
450 const contents *b_value = b.
find(current_key);
451 if (!a_value || !b_value)
continue;
452 if (*a_value != *b_value)
return false;
457 #ifdef DEBUG_SYMBOL_TABLE
461 #undef static_class_name
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
Provides a dynamically resizable ASCII character string.
Outcomes describe the state of completion for an operation.
internal_pointer_hider(internal_symbol_info< contents > *held)
internal_symbol_info< contents > * _held
internal_symbol_indexer(int elems)
internal_symbol_info(const contents &content, const basis::astring &name)
internal_symbol_list(int elems)
A hash table for storing pointers.
int elements() const
Returns the number of elements in this set.
Implements a hash table indexed on character strings.
A simple object that wraps a templated set of strings.
Maintains a list of names, where each name has a type and some contents.
basis::outcome retrieve(int index, basis::astring &symbol_name, contents &contains) const
Locates the symbol at position "index" and stores it to the parameters.
symbol_table(int estimated_elements=100)
constructs a symbol table with sufficient size for "estimated_elements".
void names(string_set &to_fill) const
returns the names of all the symbols currently held.
symbol_table & operator=(const symbol_table< contents > &to_copy)
int estimated_elements() const
returns the number of symbols the table is optimized for.
basis::outcome zap_index(int index)
zaps the entry at the specified index. slower than whack().
const basis::astring & name(int index) const
returns the name held at the "index".
symbol_table(const symbol_table< contents > &to_copy)
contents * find(const basis::astring &name) const
returns the contents held for "name" or NULL_POINTER if it wasn't found.
int dep_find(const basis::astring &name) const
Searches for a symbol by its "name".
contents & use(int index)
named equivalent for the bracket operator.
void rehash(int estimated_elements)
resizes underlying table to support "estimated_elements".
basis::outcome add(const basis::astring &name, const contents &storage)
Enters a symbol name into the table along with some contents.
contents & operator[](int index)
provides access to the symbol_table's contents at the "index".
void hash_appropriately(int estimated_elements)
Resizes the number of table slots to have space for "estimated_elements".
contents * find(const basis::astring &name, basis::string_comparator_function *comparator) const
Specialized search via a comparison method "comparator".
basis::outcome whack(const basis::astring &name)
removes a symbol from the table.
int symbols() const
returns the number of symbols listed in the table.
const contents & get(int index) const
named equivalent for the bracket operator.
#define NULL_POINTER
The value representing a pointer to nothing.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
#define bounds_return(value, low, high, to_return)
Verifies that "value" is between "low" and "high", inclusive.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
bool string_comparator_function(const astring &a, const astring &b)
returns true if the strings "a" and "b" are considered equal.
A dynamic container class that holds any kind of object via pointers.
bool sym_tab_finder_apply(const basis::astring &key, contents ¤t, void *data_link)
void pack(basis::byte_array &packed_form, const set< contents > &to_pack)
provides a way to pack any set that stores packable objects.
bool symbol_table_compare(const symbol_table< contents > &a, const symbol_table< contents > &b)
returns true if table "a" and table "b" have the same contents.
basis::string_comparator_function * _scf