symbol_table< contents > Class Template Reference

Maintains a list of names, where each name has a type and some contents. More...

#include <symbol_table.h>

Inheritance diagram for symbol_table< contents >:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 symbol_table (int max_bits=7)
 constructs a symbol table with 2^max_bits hashed slots.
 symbol_table (const symbol_table< contents > &to_copy)
 ~symbol_table ()
int symbols () const
 returns the number of symbols listed in the table.
int max_bits () const
 the number of hashing bits.
void rehash (int max_bits)
 resizes underlying table to 2^max_bits.
void hash_appropriately (int max_per_bucket)
 Resizes the number of table slots to have "max_per_bucket" per slot.
symbol_tableoperator= (const symbol_table< contents > &to_copy)
outcome add (const istring &name, const contents &storage)
 Enters a symbol name into the table along with some contents.
const istringname (int index) const
 returns the name held at the "index".
void names (string_set &to_fill) const
 returns the names of all the symbols currently held.
contents & operator[] (int index)
 provides access to the symbol_table's contents at the "index".
const contents & operator[] (int index) const
 provides a constant peek at the contents at the "index".
const contents & get (int index) const
 named equivalent for the bracket operator.
contents & use (int index)
 named equivalent for the bracket operator.
contents * find (const istring &name) const
 returns the contents held for "name" or NIL if it wasn't found.
contents * find (const istring &name, string_comparator_function *comparator) const
 Specialized search via a comparison method "comparator".
int dep_find (const istring &name) const
 Searches for a symbol by its "name".
outcome retrieve (int index, istring &symbol_name, contents &contains) const
 Locates the symbol at position "index" and stores it to the parameters.
outcome whack (const istring &name)
 removes a symbol from the table.
outcome zap_index (int index)
 zaps the entry at the specified index. slower than whack().
void reset ()

Detailed Description

template<class contents>
class symbol_table< contents >

Maintains a list of names, where each name has a type and some contents.

Definition at line 31 of file symbol_table.h.


Constructor & Destructor Documentation

template<class contents>
symbol_table< contents >::symbol_table ( int  max_bits = 7  ) 

constructs a symbol table with 2^max_bits hashed slots.

the "max_bits" dictates how large the symbol table's key space is. the number of keys that can be stored without collisions (assuming perfect distribution from hash function) will be 2^max_bits.

Definition at line 101 of file symbol_table.cpp.

template<class contents>
symbol_table< contents >::symbol_table ( const symbol_table< contents > &  to_copy  ) 

Definition at line 107 of file symbol_table.cpp.

template<class contents>
symbol_table< contents >::~symbol_table (  ) 

Definition at line 114 of file symbol_table.cpp.

References WHACK().


Member Function Documentation

template<class contents>
int symbol_table< contents >::symbols (  )  const

returns the number of symbols listed in the table.

Definition at line 162 of file symbol_table.cpp.

Referenced by application_config::add_program(), section_manager::add_section(), list_parsing::create_csv_line(), symbol_table< contents >::dep_find(), table_configurator::get_section(), section_manager::get_section_names(), symbol_table< contents >::hash_appropriately(), xml_parser::header_callback(), main(), ini_parser::merge_section(), symbol_table< contents >::name(), symbol_table< contents >::names(), symbol_table< contents >::operator=(), string_table::operator==(), symbol_table< contents >::operator[](), section_manager::replace_section(), symbol_table< contents >::retrieve(), tokenizer::symbols(), xml_parser::tag_open_callback(), and tokenizer::text_form().

template<class contents>
int symbol_table< contents >::max_bits (  )  const

the number of hashing bits.

Definition at line 121 of file symbol_table.cpp.

Referenced by symbol_table< contents >::hash_appropriately().

template<class contents>
void symbol_table< contents >::rehash ( int  max_bits  ) 

resizes underlying table to 2^max_bits.

Definition at line 125 of file symbol_table.cpp.

Referenced by symbol_table< contents >::hash_appropriately().

template<class contents>
void symbol_table< contents >::hash_appropriately ( int  max_per_bucket  ) 

Resizes the number of table slots to have "max_per_bucket" per slot.

This rehashes this symbol_table by attempting to ensure that "max_per_bucket" is the largest number of items that need to be traversed before finding a match in one hash bucket, given the current number of items and average items per bucket. note that this ignores the time spent creating the hash value to find the slot; it is just adapting to an average number of items per slot.

Definition at line 133 of file symbol_table.cpp.

References FUNCDEF, LOG, symbol_table< contents >::max_bits(), symbol_table< contents >::rehash(), and symbol_table< contents >::symbols().

template<class contents>
symbol_table< contents > & symbol_table< contents >::operator= ( const symbol_table< contents > &  to_copy  ) 

Definition at line 167 of file symbol_table.cpp.

References symbol_table< contents >::get_index(), symbol_table< contents >::reset(), and symbol_table< contents >::symbols().

template<class contents>
outcome symbol_table< contents >::add ( const istring name,
const contents &  storage 
)

Enters a symbol name into the table along with some contents.

If the name already exists in the table, then the previous contents are replaced with these, but EXISTING is returned. If this is a new entry, then NEW is returned instead.

Definition at line 299 of file symbol_table.cpp.

References common::EXISTING, FUNCDEF, common::IS_NEW, and symbol_table< contents >::name().

Referenced by ADD(), key_repository::add(), application_config::add_program(), application_config::add_startup_entry(), application_config::application_config(), table_configurator::get_section(), tokenizer::parse(), bookmark_tree::process_category(), table_configurator::put(), and test_string_table().

template<class contents>
const istring & symbol_table< contents >::name ( int  index  )  const

returns the name held at the "index".

if the index is invalid, then a bogus name is returned.

Definition at line 193 of file symbol_table.cpp.

References bounds_return, and symbol_table< contents >::symbols().

Referenced by symbol_table< contents >::add(), application_config::add_program(), list_parsing::create_csv_line(), symbol_table< contents >::dep_find(), write_build_config::execute(), symbol_table< contents >::find(), table_configurator::get_section(), section_manager::get_section_names(), main(), ini_parser::merge_section(), write_build_config::output_definition_macro(), symbol_table< contents >::retrieve(), tokenizer::text_form(), symbol_table< contents >::whack(), and symbol_table< contents >::zap_index().

template<class contents>
void symbol_table< contents >::names ( string_set to_fill  )  const

returns the names of all the symbols currently held.

Definition at line 200 of file symbol_table.cpp.

References array< contents >::reset(), and symbol_table< contents >::symbols().

Referenced by config_watcher::changed_items(), config_watcher::deleted_items(), config_watcher::new_items(), and symbol_table_compare().

template<class contents>
contents & symbol_table< contents >::operator[] ( int  index  ) 

provides access to the symbol_table's contents at the "index".

Definition at line 225 of file symbol_table.cpp.

References bounds_return, and symbol_table< contents >::symbols().

Referenced by symbol_table< istring >::get(), and symbol_table< istring >::use().

template<class contents>
const contents & symbol_table< contents >::operator[] ( int  index  )  const

provides a constant peek at the contents at the "index".

Definition at line 216 of file symbol_table.cpp.

References bounds_return, and symbol_table< contents >::symbols().

template<class contents>
const contents& symbol_table< contents >::get ( int  index  )  const [inline]

named equivalent for the bracket operator.

Definition at line 80 of file symbol_table.h.

Referenced by main().

template<class contents>
contents& symbol_table< contents >::use ( int  index  )  [inline]

named equivalent for the bracket operator.

Definition at line 82 of file symbol_table.h.

template<class contents>
contents * symbol_table< contents >::find ( const istring name  )  const

returns the contents held for "name" or NIL if it wasn't found.

Definition at line 234 of file symbol_table.cpp.

References FUNCDEF, symbol_table< contents >::name(), and NIL.

Referenced by tokenizer::exists(), FIND(), tokenizer::find(), symbol_table< contents >::find(), application_config::find_entry(), table_configurator::get(), key_repository::lock(), string_table::operator==(), bookmark_tree::process_category(), symbol_table_compare(), and test_string_table().

template<class contents>
contents * symbol_table< contents >::find ( const istring name,
string_comparator_function comparator 
) const

Specialized search via a comparison method "comparator".

Searches for a symbol by its "name" but uses a special comparison function "comparator" to determine if the name is really equal. This method is by its nature slower than the main find method, since all buckets must be searched until a match is found. It is just intended to provide extensibility.

Definition at line 282 of file symbol_table.cpp.

References symbol_table< contents >::find(), FUNCDEF, LOG, symbol_table< contents >::name(), pack(), and sym_tab_finder_apply().

template<class contents>
int symbol_table< contents >::dep_find ( const istring name  )  const

Searches for a symbol by its "name".

Returns the index or NOT_FOUND. NOTE: this is deprecated; it is far faster to use the first find method above.

Definition at line 243 of file symbol_table.cpp.

References symbol_table< contents >::name(), common::NOT_FOUND, and symbol_table< contents >::symbols().

template<class contents>
outcome symbol_table< contents >::retrieve ( int  index,
istring symbol_name,
contents &  contains 
) const

Locates the symbol at position "index" and stores it to the parameters.

retrieve() accesses the "index"th symbol in the table and returns the held contents for it as well as its name. if the outcome is OKAY, then the returned information is valid. otherwise, the search failed.

Definition at line 339 of file symbol_table.cpp.

References bounds_return, symbol_table< contents >::name(), common::NOT_FOUND, common::OKAY, and symbol_table< contents >::symbols().

template<class contents>
outcome symbol_table< contents >::whack ( const istring name  ) 

removes a symbol from the table.

this succeeds only if the symbol name is present in the table.

Definition at line 326 of file symbol_table.cpp.

References FUNCDEF, symbol_table< contents >::name(), common::NOT_FOUND, and common::OKAY.

Referenced by application_config::add_program(), table_configurator::delete_entry(), application_config::remove_program(), application_config::remove_startup_entry(), key_repository::whack(), and symbol_table< contents >::zap_index().

template<class contents>
outcome symbol_table< contents >::zap_index ( int  index  ) 

zaps the entry at the specified index. slower than whack().

Definition at line 319 of file symbol_table.cpp.

References symbol_table< contents >::name(), and symbol_table< contents >::whack().

template<class contents>
void symbol_table< contents >::reset (  ) 

Definition at line 186 of file symbol_table.cpp.

Referenced by application_config::find_section(), ini_configurator::get_section(), table_configurator::get_section(), symbol_table< contents >::operator=(), tokenizer::reset(), and test_string_table().


The documentation for this class was generated from the following files:
Generated on Fri Nov 28 04:31:02 2008 for HOOPLE Libraries by  doxygen 1.5.1