CS::Utility::StringHash< Tag > Class Template Reference
A string-to-ID hash table. More...
#include <csutil/strhash.h>

Public Member Functions | |
| void | Clear () |
| Delete all stored strings. | |
| bool | Contains (StringID< Tag > 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. | |
| bool | Delete (StringID< Tag > id) |
| Remove a string with the specified ID. | |
| bool | Delete (char const *s) |
| Remove specified string. | |
| 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. | |
| StringHash & | operator= (StringHash const &h) |
| Assignment operator. | |
| const char * | Register (const char *s, StringID< Tag > id=0) |
| Register a string with an ID. | |
| const char * | Request (StringID< Tag > id) const |
| Request the string for a given ID. | |
| StringID< Tag > | Request (const char *s) const |
| Request the ID for the given string. | |
| StringHash (StringHash const &h) | |
| Copy constructor. | |
| StringHash (size_t size=23) | |
| Constructor. | |
| ~StringHash () | |
| Destructor. | |
Detailed Description
template<typename Tag>
class CS::Utility::StringHash< Tag >
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 43 of file strhash.h.
Constructor & Destructor Documentation
| CS::Utility::StringHash< Tag >::StringHash | ( | size_t | size = 23 |
) | [inline] |
| CS::Utility::StringHash< Tag >::StringHash | ( | StringHash< Tag > const & | h | ) | [inline] |
| CS::Utility::StringHash< Tag >::~StringHash | ( | ) | [inline] |
Member Function Documentation
| void CS::Utility::StringHash< Tag >::Clear | ( | ) | [inline] |
Delete all stored strings.
- Deprecated:
- Use Empty() instead.
| bool CS::Utility::StringHash< Tag >::Contains | ( | StringID< Tag > | 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 CS::Utility::StringHash< Tag >::Contains | ( | char const * | s | ) | const [inline] |
| bool CS::Utility::StringHash< Tag >::Delete | ( | StringID< Tag > | id | ) | [inline] |
| bool CS::Utility::StringHash< Tag >::Delete | ( | char const * | s | ) | [inline] |
Remove specified string.
- Returns:
- True if a matching string was in thet set; else false.
Reimplemented in csStringHashReversible.
| void CS::Utility::StringHash< Tag >::Empty | ( | ) | [inline] |
Remove all stored strings.
Reimplemented in csStringHashReversible.
| GlobalIterator CS::Utility::StringHash< Tag >::GetIterator | ( | ) | const [inline] |
| size_t CS::Utility::StringHash< Tag >::GetSize | ( | ) | const [inline] |
| bool CS::Utility::StringHash< Tag >::IsEmpty | ( | ) | const [inline] |
| StringHash& CS::Utility::StringHash< Tag >::operator= | ( | StringHash< Tag > const & | h | ) | [inline] |
Assignment operator.
Reimplemented in csStringHashReversible.
| const char* CS::Utility::StringHash< Tag >::Register | ( | const char * | s, | |
| StringID< Tag > | id = 0 | |||
| ) | [inline] |
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 theidmakes for a good alternative to csStringSet when you do not require its extra bulk.
| const char* CS::Utility::StringHash< Tag >::Request | ( | StringID< Tag > | id | ) | const [inline] |
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.
| StringID<Tag> CS::Utility::StringHash< Tag >::Request | ( | const char * | s | ) | const [inline] |
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.
The documentation for this class was generated from the following file:
- csutil/strhash.h
Generated for Crystal Space 2.1 by doxygen 1.6.1
