Provide a dual-directional mapping between strings and integers. More...
#include <dictionary.h>
Public Member Functions | |
void | clear () |
Clear the allocated memory. | |
dictionary (const dictionary &dic) | |
Copy constructor. Places all the string in one contiguous buffer. | |
dictionary () | |
Default constructor. Generates one (NULL) entry. | |
const char * | find (const char *str) const |
If the input string is found in the dictionary, it returns the string. | |
uint32_t | insert (const char *str) |
Insert a string to the dictionary. | |
uint32_t | insertRaw (char *str) |
Non-copying insert. | |
const char * | operator[] (uint32_t i) const |
Return a string corresponding to the integer. | |
uint32_t | operator[] (const char *str) const |
Convert a string to its integer code. | |
int | read (const char *name) |
Read the content of the named file. | |
uint32_t | size () const |
Return the number of valid (not null) strings in the dictionary. | |
void | swap (dictionary &) |
Swap the content of two dictionaries. | |
int | write (const char *name) const |
Write the content of the dictionary to the named file. | |
Protected Member Functions | |
void | copy (const dictionary &rhs) |
Copy function. Use copy constructor and swap the content. | |
int | readKeys (const char *, FILE *) |
Read the ordered strings. | |
int | readRaw (const char *, FILE *) |
Read the raw strings. | |
Protected Attributes | |
array_t< char * > | buffer_ |
Member varaible buffer_ contains a list of pointers to the memory that holds the strings. | |
array_t< uint32_t > | code_ |
Member variable code_ contains the integer code for each string in key_. | |
array_t< const char * > | key_ |
Member variable key_ contains the string values in alphabetic order. | |
array_t< const char * > | raw_ |
Member variable raw_ contains the string values in the order of the code assignment. |
Provide a dual-directional mapping between strings and integers.
A utility class used by ibis::category. The NULL string is always the 0th string.
const char * ibis::dictionary::find | ( | const char * | str | ) | const [inline] |
If the input string is found in the dictionary, it returns the string.
Otherwise it returns null pointer. This function makes a little easier to determine whether a string is in a dictionary.
uint32_t ibis::dictionary::insert | ( | const char * | str | ) |
Insert a string to the dictionary.
Returns the integer value assigned to the string. A copy of the string is stored internally.
References ibis::util::copy(), ibis::gVerbose, and ibis::util::strnewdup().
Referenced by ibis::category::category(), and ibis::column::string2int().
uint32_t ibis::dictionary::insertRaw | ( | char * | str | ) |
Non-copying insert.
Do not make a copy of the input string. Transfers the ownership of str
to the dictionary. Caller needs to check whether it is a new word in the dictionary. If it is not a new word in the dictionary, the dictionary does not take ownership of the string argument.
References ibis::gVerbose.
const char * ibis::dictionary::operator[] | ( | uint32_t | i | ) | const [inline] |
Return a string corresponding to the integer.
If the index is beyond the valid range, i.e., i > size(), then a null pointer will be returned.
uint32_t ibis::dictionary::operator[] | ( | const char * | str | ) | const |
Convert a string to its integer code.
Returns 0 for empty (null) strings, 1:size() for strings in the dictionary, and dictionary::size()+1 for unknown values.
References ibis::gVerbose.
int ibis::dictionary::read | ( | const char * | name | ) |
Read the content of the named file.
The file content is read into the buffer in one-shot and then digested.
References ibis::gVerbose.
int ibis::dictionary::readKeys | ( | const char * | evt, |
FILE * | fptr | ||
) | [protected] |
Read the ordered strings.
This function process the data produced by the write function. On successful completion, it returns 0.
References ibis::gVerbose.
int ibis::dictionary::readRaw | ( | const char * | evt, |
FILE * | fptr | ||
) | [protected] |
Read the raw strings.
This is the older style dictionary that contains the raw strings. On successful completion, this function returns 1.
References ibis::gVerbose, and ibis::util::sortStrings().
int ibis::dictionary::write | ( | const char * | name | ) | const |
Write the content of the dictionary to the named file.
The existing content in the named file is overwritten. The content of the dictionary file is as follows.
References ibis::gVerbose.
Referenced by ibis::category::category().
array_t<char*> ibis::dictionary::buffer_ [protected] |
Member varaible buffer_ contains a list of pointers to the memory that holds the strings.
Referenced by dictionary(), and swap().
array_t<uint32_t> ibis::dictionary::code_ [protected] |
Member variable code_ contains the integer code for each string in key_.
Referenced by dictionary(), and swap().
array_t<const char*> ibis::dictionary::raw_ [protected] |
Member variable raw_ contains the string values in the order of the code assignment.
Referenced by dictionary(), and swap().
![]() |