Ptex
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
PtexHashMap< KeyType, DataType, HashFn > Class Template Reference

A lightweight hash table. More...

#include <PtexHashMap.h>

Classes

struct  Entry
 
class  iterator
 Internal class used to provide iteration through the hash table. More...
 
struct  value_type
 

Public Types

typedef KeyType key_type
 
typedef DataType data_type
 
typedef HashFn hash_fn
 

Public Member Functions

iterator begin () const
 Returns an iterator referencing the beginning of the table. More...
 
iterator end () const
 Returns an iteraot referencing the location just beyond the table. More...
 
 PtexHashMap ()
 Default contructor initializes the hash table. More...
 
 ~PtexHashMap ()
 Non-Virtual destructor by design, clears the entries in the hash table. More...
 
DataTypeoperator[] (const KeyType &key)
 Locates an entry, creating a new one if necessary. More...
 
iterator find (const KeyType &key) const
 Locates an entry, without creating a new one. More...
 
bool erase (const KeyType &key)
 Will remove an entry. It will return TRUE if an entry was found. More...
 
iterator erase (iterator iter)
 Will remove an entry. It will return a iterator to the next element. More...
 
void clear ()
 clear will remove all entries and free the table More...
 
int size () const
 number of entries in the hash More...
 

Private Member Functions

 PtexHashMap (const PtexHashMap &)
 Copy constructor prohibited by design. More...
 
bool operator= (const PtexHashMap &)
 Assignment operator prohibited by design. More...
 
Entry ** locate (const KeyType &key) 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...
 

Private Attributes

int _numEntries
 
int _numBuckets
 
int _bucketMask
 
Entry ** _buckets
 
HashFn hash
 

Friends

class iterator
 

Detailed Description

template<typename KeyType, typename DataType, typename HashFn>
class PtexHashMap< KeyType, DataType, HashFn >

A lightweight hash table.

The hash table automatically doubles in size when it is more than 50% full.

The interface is mostely compatible with std::hash_map<>, though not all methods are provided. Methods provided:

Author
brentb
Version
1.0 brentb 11/01/2000: Initial version
1.1 longson 06/26/2001: Added file and class comment headers
1.2 brentb 105/2006: Generalized IntDict into general hash map

Definition at line 85 of file PtexHashMap.h.

Member Typedef Documentation

template<typename KeyType, typename DataType, typename HashFn>
typedef DataType PtexHashMap< KeyType, DataType, HashFn >::data_type

Definition at line 91 of file PtexHashMap.h.

template<typename KeyType, typename DataType, typename HashFn>
typedef HashFn PtexHashMap< KeyType, DataType, HashFn >::hash_fn

Definition at line 92 of file PtexHashMap.h.

template<typename KeyType, typename DataType, typename HashFn>
typedef KeyType PtexHashMap< KeyType, DataType, HashFn >::key_type

Definition at line 87 of file PtexHashMap.h.

Constructor & Destructor Documentation

template<typename KeyType, typename DataType, typename HashFn>
PtexHashMap< KeyType, DataType, HashFn >::PtexHashMap ( )
inline

Default contructor initializes the hash table.

Definition at line 158 of file PtexHashMap.h.

template<typename KeyType, typename DataType, typename HashFn>
PtexHashMap< KeyType, DataType, HashFn >::~PtexHashMap ( )
inline

Non-Virtual destructor by design, clears the entries in the hash table.

Definition at line 160 of file PtexHashMap.h.

template<typename KeyType, typename DataType, typename HashFn>
PtexHashMap< KeyType, DataType, HashFn >::PtexHashMap ( const PtexHashMap< KeyType, DataType, HashFn > &  )
private

Copy constructor prohibited by design.

Member Function Documentation

template<typename KeyType, typename DataType, typename HashFn>
iterator PtexHashMap< KeyType, DataType, HashFn >::begin ( ) const
inline

Returns an iterator referencing the beginning of the table.

Definition at line 136 of file PtexHashMap.h.

Referenced by PtexHashMap< KeyType, DataType, HashFn >::clear(), and PtexReader::~PtexReader().

template<class KeyType , class DataType , class HashFn >
void PtexHashMap< KeyType, DataType, HashFn >::clear ( )
template<typename KeyType, typename DataType, typename HashFn>
iterator PtexHashMap< KeyType, DataType, HashFn >::end ( ) const
inline
template<class KeyType, class DataType , class HashFn >
bool PtexHashMap< KeyType, DataType, HashFn >::erase ( const KeyType &  key)

Will remove an entry. It will return TRUE if an entry was found.

Definition at line 303 of file PtexHashMap.h.

References PtexHashMap< KeyType, DataType, HashFn >::end(), and PtexHashMap< KeyType, DataType, HashFn >::find().

Referenced by PtexHashMap< KeyType, DataType, HashFn >::clear().

template<class KeyType, class DataType , class HashFn >
PtexHashMap< KeyType, DataType, HashFn >::iterator PtexHashMap< KeyType, DataType, HashFn >::erase ( iterator  iter)

Will remove an entry. It will return a iterator to the next element.

Definition at line 314 of file PtexHashMap.h.

References PtexHashMap< KeyType, DataType, HashFn >::_numEntries, PtexHashMap< KeyType, DataType, HashFn >::iterator::e, and PtexHashMap< KeyType, DataType, HashFn >::Entry::next.

template<class KeyType, class DataType , class HashFn >
PtexHashMap< KeyType, DataType, HashFn >::iterator PtexHashMap< KeyType, DataType, HashFn >::find ( const KeyType &  key) const

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, both the returned key and value pointers will be NULL.

Definition at line 246 of file PtexHashMap.h.

References PtexHashMap< KeyType, DataType, HashFn >::_bucketMask, PtexHashMap< KeyType, DataType, HashFn >::iterator::b, PtexHashMap< KeyType, DataType, HashFn >::iterator::e, PtexHashMap< KeyType, DataType, HashFn >::end(), PtexHashMap< KeyType, DataType, HashFn >::iterator::h, PtexHashMap< KeyType, DataType, HashFn >::hash, and PtexHashMap< KeyType, DataType, HashFn >::locate().

Referenced by PtexHashMap< KeyType, DataType, HashFn >::erase().

template<class KeyType , class DataType , class HashFn >
void PtexHashMap< KeyType, DataType, HashFn >::grow ( )
private
template<typename KeyType, typename DataType, typename HashFn>
Entry** PtexHashMap< KeyType, DataType, HashFn >::locate ( const KeyType &  key) const
inlineprivate

Returns a pointer to the desired entry, based on the key.

Definition at line 204 of file PtexHashMap.h.

Referenced by PtexHashMap< KeyType, DataType, HashFn >::find(), and PtexHashMap< KeyType, DataType, HashFn >::operator[]().

template<typename KeyType, typename DataType, typename HashFn>
bool PtexHashMap< KeyType, DataType, HashFn >::operator= ( const PtexHashMap< KeyType, DataType, HashFn > &  )
private

Assignment operator prohibited by design.

template<class KeyType, class DataType , class HashFn >
DataType & PtexHashMap< KeyType, DataType, HashFn >::operator[] ( const KeyType &  key)
template<typename KeyType, typename DataType, typename HashFn>
int PtexHashMap< KeyType, DataType, HashFn >::size ( ) const
inline

number of entries in the hash

Definition at line 186 of file PtexHashMap.h.

Friends And Related Function Documentation

template<typename KeyType, typename DataType, typename HashFn>
friend class iterator
friend

Member Data Documentation

template<typename KeyType, typename DataType, typename HashFn>
int PtexHashMap< KeyType, DataType, HashFn >::_bucketMask
private
template<typename KeyType, typename DataType, typename HashFn>
Entry** PtexHashMap< KeyType, DataType, HashFn >::_buckets
private
template<typename KeyType, typename DataType, typename HashFn>
int PtexHashMap< KeyType, DataType, HashFn >::_numBuckets
private
template<typename KeyType, typename DataType, typename HashFn>
int PtexHashMap< KeyType, DataType, HashFn >::_numEntries
private
template<typename KeyType, typename DataType, typename HashFn>
HashFn PtexHashMap< KeyType, DataType, HashFn >::hash
private

The documentation for this class was generated from the following file: