CrystalSpace

Public API Reference

csStringHash Class Reference

A string-to-ID hash table. More...

#include <csutil/strhash.h>

List of all members.

Public Types

typedef HashType::ConstGlobalIterator GlobalIterator

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 (csStringHash const &h)
 Copy constructor.
 csStringHash (size_t size=23)
 Constructor.
bool Delete (csStringID 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.
csStringHashoperator= (csStringHash const &h)
 Assignment operator.
const char * Register (const char *s, csStringID id=0)
 Register a string with an ID.
const char * Request (csStringID id) const
 Request the string for a given ID.
csStringID Request (const char *s) const
 Request the ID for the given string.
 ~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]

Copy constructor.

Definition at line 54 of file strhash.h.

csStringHash::~csStringHash (  ) 

Destructor.


Member Function Documentation

void csStringHash::Clear (  )  [inline]

Delete all stored strings.

Deprecated:
Use Empty() instead.

Definition at line 143 of file strhash.h.

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.

Definition at line 116 of file strhash.h.

bool csStringHash::Contains ( char const *  s  )  const [inline]

Check if the hash contains a particular string.

Remarks:
This is rigidly equivalent to return Request(s) != csInvalidStringID.

Definition at line 105 of file strhash.h.

References csInvalidStringID.

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).

bool csStringHash::Delete ( char const *  s  ) 

Remove specified string.

Returns:
True if a matching string was in thet set; else false.

void csStringHash::Empty (  ) 

Remove all stored strings.

GlobalIterator csStringHash::GetIterator (  )  const [inline]

Return an iterator for the string hash which iterates over all elements.

Warning:
Modifying the hash while you have open iterators will result undefined behaviour.

Definition at line 163 of file strhash.h.

size_t csStringHash::GetSize (  )  const [inline]

Get the number of elements in the hash.

Definition at line 147 of file strhash.h.

bool csStringHash::IsEmpty (  )  const [inline]

Return true if the hash is empty.

Remarks:
Rigidly equivalent to return GetSize() == 0, but more idiomatic.

Definition at line 155 of file strhash.h.

csStringHash& csStringHash::operator= ( csStringHash const &  h  )  [inline]

Assignment operator.

Definition at line 58 of file strhash.h.

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 the id makes for a good alternative to csStringSet when you do not require its extra bulk.

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, in which reverse lookups are optimized.

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.


The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.4.7