Ptex
|
A string-keyed dictionary template, using a hash table. More...
#include <PtexDict.h>
Classes | |
class | const_iterator |
Internal class used to provide iteration through the dictionary. More... | |
class | Entry |
This internal structure is used to store the dictionary elements. More... | |
class | iterator |
Internal class used to provide iteration through the dictionary. More... | |
struct | value_type |
Internal class used to provide a return value for the value type. More... | |
Public Types | |
typedef const char * | key_type |
This is the lookup type. More... | |
typedef T | mapped_type |
The data type stored. More... | |
Public Member Functions | |
PtexDict () | |
Default contructor initializes the dictionary. More... | |
virtual | ~PtexDict () |
clears the entries in the dictionary More... | |
T & | operator[] (const char *key) |
Locates an entry, creating a new one if necessary. More... | |
iterator | begin () |
Returns an iterator referencing the beginning of the table. More... | |
iterator | end () |
Returns an iterator referencing the end of the table. More... | |
const_iterator | begin () const |
Const access to the beginning of the list. More... | |
const_iterator | end () const |
Const access to the end of the list. More... | |
iterator | find (const char *key) |
Locates an entry, without creating a new one. More... | |
const_iterator | find (const char *key) const |
works the same as find above, but returns a constant iterator. More... | |
bool | erase (const char *key) |
Will remove an entry. It will return TRUE if an entry was found. More... | |
iterator | erase (iterator iter) |
Removes the entry referenced by the iterator, from the dictionary. More... | |
void | clear () |
clear will remove all entries from the dictionary. O(n) More... | |
int | size () const |
Returns the number of entries in the dictionary. O(1) time to call. More... | |
Private Member Functions | |
PtexDict (const PtexDict &) | |
Copy constructor prohibited by design. More... | |
PtexDict & | operator= (const PtexDict &) |
Assignment operator prohibited by design. More... | |
int | hash (const char *key, int &keylen) const |
Returns the integer hash index for the key and length of the key. More... | |
Entry ** | locate (const char *key, int &keylen, int &hashval) const |
Returns a pointer to the desired entry, based on the key. More... | |
void | grow () |
Used to increase the size of the table if necessary. More... | |
Static Private Member Functions | |
static bool | streq (const char *s1, const char *s2, int len) |
Used for string compares, much faster then strcmp. More... | |
Private Attributes | |
int | _numEntries |
The number of entries in the dictionary. More... | |
int | _numBuckets |
The number of buckets in use. More... | |
int | _bucketMask |
The mask for the buckets. More... | |
Entry ** | _buckets |
The pointer to the bucket structure. More... | |
Friends | |
class | iterator |
forward declared class More... | |
class | const_iterator |
A string-keyed dictionary template, using a hash table.
An efficient string dictionary template. A hash table is used that automatically doubles in size when it is more than 50% full. It is hard-coded to use string keys for efficiency.
The interface is compatible with std::hash_map<>, though not all methods are provided. Methods provided:
Unlike std::hash_map<>, PtexDict doesn't have to construct a string object to do a lookup. As a result, it is about 4-10 times faster depending on the length of the keys. And when compiling non-optimized, it is 6-10 times faster.
We have decided NOT to follow the coding standard's naming comvention for this class, since it needed to remain generic, and compatible with the STL std::hash_map<> class.
Definition at line 111 of file PtexDict.h.
This is the lookup type.
Definition at line 121 of file PtexDict.h.
typedef T PtexDict< T >::mapped_type |
The data type stored.
Definition at line 122 of file PtexDict.h.
Default contructor initializes the dictionary.
Definition at line 138 of file PtexDict.h.
clears the entries in the dictionary
Definition at line 140 of file PtexDict.h.
Copy constructor prohibited by design.
Returns an iterator referencing the beginning of the table.
Definition at line 149 of file PtexDict.h.
Referenced by PtexDict< T >::clear(), PtexReaderCache::purgeAll(), and PtexReaderCache::removeBlankEntries().
|
inline |
Const access to the beginning of the list.
Definition at line 165 of file PtexDict.h.
void PtexDict< T >::clear | ( | ) |
clear will remove all entries from the dictionary. O(n)
Definition at line 588 of file PtexDict.h.
References PtexDict< T >::_buckets, PtexDict< T >::_numBuckets, PtexDict< T >::_numEntries, PtexDict< T >::begin(), PtexDict< T >::end(), and PtexDict< T >::erase().
Referenced by PtexDict< PtexReader * >::~PtexDict().
Returns an iterator referencing the end of the table.
Definition at line 162 of file PtexDict.h.
Referenced by PtexDict< T >::clear(), PtexDict< T >::find(), PtexReaderCache::purge(), PtexReaderCache::purgeAll(), and PtexReaderCache::removeBlankEntries().
|
inline |
Const access to the end of the list.
Definition at line 178 of file PtexDict.h.
bool PtexDict< T >::erase | ( | const char * | key | ) |
Will remove an entry. It will return TRUE if an entry was found.
Definition at line 555 of file PtexDict.h.
References PtexDict< T >::find().
Referenced by PtexDict< T >::clear(), PtexReaderCache::purge(), PtexReaderCache::purgeAll(), and PtexReaderCache::removeBlankEntries().
Removes the entry referenced by the iterator, from the dictionary.
It will return a iterator to the next element, or will equal the return value of end() if there is nothing else to erase. O(1)
Definition at line 566 of file PtexDict.h.
References PtexDict< T >::iterator::_e, PtexDict< T >::Entry::_next, PtexDict< T >::_numEntries, and PtexDict< T >::Entry::~Entry().
Locates an entry, without creating a new one.
find will locate an entry, but won't create a new one. The result is returned as a pair of key and value. The returned key points to the internal key string and will remain valid until the entry is deleted. If the key is not found, the returned iterator will be equal to the value returned by end(), and the iterator will be equal to false. O(1)
return a valid iterator if we found an entry, else return end()
Definition at line 478 of file PtexDict.h.
References PtexDict< T >::_bucketMask, PtexDict< T >::end(), PtexDict< T >::iterator, and PtexDict< T >::locate().
Referenced by PtexDict< T >::erase(), and PtexReaderCache::purge().
PtexDict< T >::const_iterator PtexDict< T >::find | ( | const char * | key | ) | const |
works the same as find above, but returns a constant iterator.
return a valid iterator if we found an entry, else return end()
Definition at line 489 of file PtexDict.h.
References PtexDict< T >::_bucketMask, PtexDict< T >::const_iterator, PtexDict< T >::end(), and PtexDict< T >::locate().
|
private |
Used to increase the size of the table if necessary.
Definition at line 529 of file PtexDict.h.
References PtexDict< T >::_bucketMask, PtexDict< T >::_buckets, PtexDict< T >::Entry::_next, and PtexDict< T >::_numBuckets.
Referenced by PtexDict< T >::operator[]().
|
inlineprivate |
Returns the integer hash index for the key and length of the key.
Definition at line 237 of file PtexDict.h.
Referenced by PtexDict< PtexReader * >::locate().
|
inlineprivate |
Returns a pointer to the desired entry, based on the key.
Definition at line 249 of file PtexDict.h.
Referenced by PtexDict< T >::find(), and PtexDict< T >::operator[]().
Assignment operator prohibited by design.
Locates an entry, creating a new one if necessary.
operator[] will look up an entry and return the value. A new entry will be created (using the default ctor for T) if one doesn't exist.
Definition at line 500 of file PtexDict.h.
References PtexDict< T >::_bucketMask, PtexDict< T >::_buckets, PtexDict< T >::Entry::_hashval, PtexDict< T >::Entry::_key, PtexDict< T >::Entry::_keylen, PtexDict< T >::Entry::_next, PtexDict< T >::_numBuckets, PtexDict< T >::_numEntries, PtexDict< T >::Entry::_u, PtexDict< T >::Entry::_val, PtexDict< T >::grow(), if(), PtexDict< T >::locate(), and PtexDict< T >::value_type::second.
|
inline |
Returns the number of entries in the dictionary. O(1) time to call.
Definition at line 202 of file PtexDict.h.
|
inlinestaticprivate |
Used for string compares, much faster then strcmp.
This is MUCH faster than strcmp and even memcmp, partly because it is inline and partly because it can do 4 chars at a time
Definition at line 264 of file PtexDict.h.
Referenced by PtexDict< PtexReader * >::locate().
|
friend |
Definition at line 119 of file PtexDict.h.
Referenced by PtexDict< PtexReader * >::begin(), PtexDict< PtexReader * >::end(), and PtexDict< T >::find().
|
friend |
forward declared class
Definition at line 117 of file PtexDict.h.
Referenced by PtexDict< PtexReader * >::begin(), PtexDict< PtexReader * >::end(), and PtexDict< T >::find().
|
private |
The mask for the buckets.
Definition at line 286 of file PtexDict.h.
Referenced by PtexDict< T >::find(), PtexDict< T >::grow(), PtexDict< PtexReader * >::locate(), and PtexDict< T >::operator[]().
The pointer to the bucket structure.
Definition at line 287 of file PtexDict.h.
Referenced by PtexDict< PtexReader * >::begin(), PtexDict< T >::clear(), PtexDict< T >::grow(), PtexDict< PtexReader * >::locate(), PtexDict< T >::iterator::operator++(), and PtexDict< T >::operator[]().
|
private |
The number of buckets in use.
Definition at line 285 of file PtexDict.h.
Referenced by PtexDict< PtexReader * >::begin(), PtexDict< T >::clear(), PtexDict< T >::grow(), PtexDict< T >::iterator::operator++(), and PtexDict< T >::operator[]().
|
private |
The number of entries in the dictionary.
Definition at line 284 of file PtexDict.h.
Referenced by PtexDict< T >::clear(), PtexDict< T >::erase(), PtexDict< T >::operator[](), and PtexDict< PtexReader * >::size().