strusBase  0.17
Classes | Public Types | Public Member Functions | List of all members
strus::SymbolTable Class Reference

Map of strings to indices not freed till end of table life time. More...

#include <symbolTable.hpp>

Classes

struct  HashFunc
 
struct  Key
 Key of symbol table. More...
 
struct  MapKeyEqual
 
struct  MapKeyLess
 

Public Types

typedef std::vector< const
char * >::const_iterator 
const_inv_iterator
 

Public Member Functions

 SymbolTable (ErrorBufferInterface *errorhnd_)
 Default constructor. More...
 
 ~SymbolTable ()
 Destructor. More...
 
uint32_t getOrCreate (const std::string &key)
 Get handle ( >= 1) associated with key, create one if not defined. More...
 
uint32_t getOrCreate (const char *key, std::size_t keysize)
 Get handle ( >= 1) associated with key, create one if not defined. More...
 
uint32_t get (const std::string &key) const
 Get handle associated with key or 0 if not defined. More...
 
uint32_t get (const char *key, std::size_t keysize) const
 Get handle associated with key or 0 if not defined. More...
 
const char * key (const uint32_t &id) const
 Inverse lookup, get key of handle. More...
 
std::size_t size () const
 Get number of elements defined. More...
 
bool empty () const
 Evaluate if the symbol table is empty, without any definitions. More...
 
const_inv_iterator inv_begin () const
 Get start iterator of inv. More...
 
const_inv_iterator inv_end () const
 Get end iterator of inv. More...
 
bool isNew () const
 Evaluate if the last symbol retrieved with getOrCreate was new. More...
 
void * allocBlock (unsigned int blocksize, unsigned int elemsize)
 Allocate a block in the context of the symbol table. More...
 
void clear ()
 Free all keys allocated. More...
 

Detailed Description

Map of strings to indices not freed till end of table life time.

Note
Suitable for symbol tables of languages (DSL)

Member Typedef Documentation

typedef std::vector<const char*>::const_iterator strus::SymbolTable::const_inv_iterator

Constructor & Destructor Documentation

strus::SymbolTable::SymbolTable ( ErrorBufferInterface errorhnd_)
inlineexplicit

Default constructor.

strus::SymbolTable::~SymbolTable ( )

Destructor.

Member Function Documentation

void* strus::SymbolTable::allocBlock ( unsigned int  blocksize,
unsigned int  elemsize 
)

Allocate a block in the context of the symbol table.

Note
Useful for building structures with symbols
Parameters
[in]blocksizenumber of elements to allocate
[in]elemsizesize of one element to allocate in bytes
Returns
the block allocated (not freed till end of symbol table life time)
void strus::SymbolTable::clear ( )

Free all keys allocated.

bool strus::SymbolTable::empty ( ) const
inline

Evaluate if the symbol table is empty, without any definitions.

Returns
true if yes
uint32_t strus::SymbolTable::get ( const std::string &  key) const

Get handle associated with key or 0 if not defined.

Parameters
[in]keystring
Returns
the handle for the key or 0 if not defined
uint32_t strus::SymbolTable::get ( const char *  key,
std::size_t  keysize 
) const

Get handle associated with key or 0 if not defined.

Parameters
[in]keykey string poiner
[in]keysizesize of key in bytes
Returns
the handle for the key or 0 if not defined
uint32_t strus::SymbolTable::getOrCreate ( const std::string &  key)

Get handle ( >= 1) associated with key, create one if not defined.

Parameters
[in]keystring
Returns
the handle for the key or 0 on a memory allocation error
uint32_t strus::SymbolTable::getOrCreate ( const char *  key,
std::size_t  keysize 
)

Get handle ( >= 1) associated with key, create one if not defined.

Parameters
[in]keykey string poiner
[in]keysizesize of key in bytes
Returns
the handle for the key or 0 on a memory allocation error
const_inv_iterator strus::SymbolTable::inv_begin ( ) const
inline

Get start iterator of inv.

const_inv_iterator strus::SymbolTable::inv_end ( ) const
inline

Get end iterator of inv.

bool strus::SymbolTable::isNew ( ) const
inline

Evaluate if the last symbol retrieved with getOrCreate was new.

Returns
true if the last symbol retrieved with getOrCreate was new
const char* strus::SymbolTable::key ( const uint32_t &  id) const

Inverse lookup, get key of handle.

Parameters
[in]idkey handle
Returns
the key string
std::size_t strus::SymbolTable::size ( ) const
inline

Get number of elements defined.

Returns
the number of elements defined

The documentation for this class was generated from the following file: