csStringHash Class Reference
A string-to-ID hash table. More...
#include <csutil/strhash.h>

Public Member Functions | |
void | Clear () |
Delete all stored strings. | |
bool | Contains (csStringID id) const |
Check if the hash contains a string with a particular ID. | |
bool | Contains (char const *s) const |
Check if the hash contains a particular string. | |
csStringHash (size_t size=23) | |
Constructor. | |
csStringHash (csStringHash const &h) | |
Copy constructor. | |
bool | Delete (char const *s) |
Remove specified string. | |
bool | Delete (csStringID id) |
Remove a string with the specified ID. | |
void | Empty () |
Remove all stored strings. | |
GlobalIterator | GetIterator () const |
Return an iterator for the string hash which iterates over all elements. | |
size_t | GetSize () const |
Get the number of elements in the hash. | |
bool | IsEmpty () const |
Return true if the hash is empty. | |
csStringHash & | operator= (csStringHash const &h) |
Assignment operator. | |
const char * | Register (const char *s, csStringID id=0) |
Register a string with an ID. | |
csStringID | Request (const char *s) const |
Request the ID for the given string. | |
const char * | Request (csStringID id) const |
Request the string for a given ID. | |
~csStringHash () | |
Destructor. |
Detailed Description
A string-to-ID hash table.
Useful when you need to work with strings but want the performance characteristics of simple numeric comparisons. Register a string with a unique numeric ID and then compare ID's rather than comparing strings. You can fetch a string's ID via Request().
- See also:
- csStringSet
Definition at line 38 of file strhash.h.
Constructor & Destructor Documentation
csStringHash::csStringHash | ( | size_t | size = 23 |
) |
Constructor.
csStringHash::csStringHash | ( | csStringHash const & | h | ) | [inline] |
csStringHash::~csStringHash | ( | ) |
Destructor.
Member Function Documentation
void csStringHash::Clear | ( | ) | [inline] |
Delete all stored strings.
- Deprecated:
- Use Empty() instead.
bool csStringHash::Contains | ( | char const * | s | ) | const [inline] |
bool csStringHash::Contains | ( | csStringID | id | ) | const [inline] |
Check if the hash contains a string with a particular ID.
- Remarks:
- This is rigidly equivalent to
return Request(id) != NULL
, but more idiomatic.
- Warning:
- This operation is slow. If you need to check containment of ID's frequently, then instead consider using csStringSet, in which such checks are optimized.
bool csStringHash::Delete | ( | csStringID | id | ) |
Remove a string with the specified ID.
- Returns:
- True if a matching string was in thet set; else false.
- Remarks:
- If more than one string is associated with the ID, then one is removed (but specifically which one is unspecified).
Reimplemented in csStringHashReversible.
bool csStringHash::Delete | ( | char const * | s | ) |
Remove specified string.
- Returns:
- True if a matching string was in thet set; else false.
Reimplemented in csStringHashReversible.
void csStringHash::Empty | ( | ) |
Remove all stored strings.
Reimplemented in csStringHashReversible.
GlobalIterator csStringHash::GetIterator | ( | ) | const [inline] |
size_t csStringHash::GetSize | ( | ) | const [inline] |
bool csStringHash::IsEmpty | ( | ) | const [inline] |
csStringHash& csStringHash::operator= | ( | csStringHash const & | h | ) | [inline] |
const char* csStringHash::Register | ( | const char * | s, | |
csStringID | id = 0 | |||
) |
Register a string with an ID.
- Parameters:
-
s The string with which to associate the ID. id A numeric value with which to identify this string.
- Returns:
- A pointer to the copy of the string in this hash.
- Remarks:
- If the string is already registered with a different ID, the old ID will be replaced with the one specified here. If you would like the convenience of having the ID assigned automatically, then consider using csStringSet, instead.
-
If you do not care about the ID, but instead simply want to use the hash as a string set which merely records if a string is present, then you can omit
id
. To find out if a string is contained in the set, invoke Contains(). The same functionality can be accomplished via csStringSet, however csStringSet is more heavyweight because it also maintains a reverse-mapping from ID to string. Omitting theid
makes for a good alternative to csStringSet when you do not require its extra bulk.
Reimplemented in csStringHashReversible.
csStringID csStringHash::Request | ( | const char * | s | ) | const |
Request the ID for the given string.
- Returns:
- The string's ID or csInvalidStringID if the string has not yet been registered.
Reimplemented in csStringHashReversible.
const char* csStringHash::Request | ( | csStringID | id | ) | const |
Request the string for a given ID.
- Returns:
- The string associated with the given ID, or the null pointer if the string has not yet been registered. If more than one string is associated with the ID, then one is returned (but specifically which one is unspecified).
- Warning:
- This operation is slow. If you need to perform reverse lookups frequently, then instead consider using csStringSet or csStringHashReversible, in which reverse lookups are optimized.
Reimplemented in csStringHashReversible.
The documentation for this class was generated from the following file:
- csutil/strhash.h
Generated for Crystal Space 1.4.1 by doxygen 1.7.1