Ptex: PtexHashMap< KeyType, DataType, HashFn > Class Template Reference

Ptex

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

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...
DataType & | operator[] (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:

- iterator begin();
- iterator end();
- DataType& operator[] (KeyType key);
- iterator find(KeyType key) const;
- bool erase(KeyType key);
- iterator erase(iterator);
- void clear();
- int size() const;

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

clear will remove all entries and free the table

Definition at line 336 of file PtexHashMap.h.

References PtexHashMap< KeyType, DataType, HashFn >::_buckets, PtexHashMap< KeyType, DataType, HashFn >::_numBuckets, PtexHashMap< KeyType, DataType, HashFn >::_numEntries, PtexHashMap< KeyType, DataType, HashFn >::begin(), PtexHashMap< KeyType, DataType, HashFn >::end(), and PtexHashMap< KeyType, DataType, HashFn >::erase().

Referenced by PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher >::~PtexHashMap().

template<typename KeyType, typename DataType, typename HashFn>

iterator PtexHashMap< KeyType, DataType, HashFn >::end | ( |  | ) | const
| inline

Returns an iteraot referencing the location just beyond the table.

Definition at line 149 of file PtexHashMap.h.

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

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

Used to increase the size of the table if necessary.

Definition at line 277 of file PtexHashMap.h.

References PtexHashMap< KeyType, DataType, HashFn >::_bucketMask, PtexHashMap< KeyType, DataType, HashFn >::_buckets, PtexHashMap< KeyType, DataType, HashFn >::_numBuckets, PtexHashMap< KeyType, DataType, HashFn >::hash, and PtexHashMap< KeyType, DataType, HashFn >::Entry::next.

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

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

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 DataType) if one doesn't exist.

Definition at line 259 of file PtexHashMap.h.

References PtexHashMap< KeyType, DataType, HashFn >::_bucketMask, PtexHashMap< KeyType, DataType, HashFn >::_buckets, PtexHashMap< KeyType, DataType, HashFn >::_numBuckets, PtexHashMap< KeyType, DataType, HashFn >::_numEntries, PtexHashMap< KeyType, DataType, HashFn >::grow(), PtexHashMap< KeyType, DataType, HashFn >::hash, if(), PtexHashMap< KeyType, DataType, HashFn >::Entry::key, PtexHashMap< KeyType, DataType, HashFn >::locate(), PtexHashMap< KeyType, DataType, HashFn >::Entry::next, and PtexHashMap< KeyType, DataType, HashFn >::Entry::val.

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

Definition at line 194 of file PtexHashMap.h.

Referenced by PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher >::begin(), and PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher >::end().

## Member Data Documentation

template<typename KeyType, typename DataType, typename HashFn>

int PtexHashMap< KeyType, DataType, HashFn >::_bucketMask
| private

Definition at line 218 of file PtexHashMap.h.

Referenced by PtexHashMap< KeyType, DataType, HashFn >::find(), PtexHashMap< KeyType, DataType, HashFn >::grow(), PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher >::locate(), and PtexHashMap< KeyType, DataType, HashFn >::operator[]().

template<typename KeyType, typename DataType, typename HashFn>

Entry** PtexHashMap< KeyType, DataType, HashFn >::_buckets
| private

Definition at line 219 of file PtexHashMap.h.

Referenced by PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher >::begin(), PtexHashMap< KeyType, DataType, HashFn >::clear(), PtexHashMap< KeyType, DataType, HashFn >::grow(), PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher >::locate(), PtexHashMap< KeyType, DataType, HashFn >::iterator::operator++(), and PtexHashMap< KeyType, DataType, HashFn >::operator[]().

template<typename KeyType, typename DataType, typename HashFn>

int PtexHashMap< KeyType, DataType, HashFn >::_numBuckets
| private

Definition at line 217 of file PtexHashMap.h.

Referenced by PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher >::begin(), PtexHashMap< KeyType, DataType, HashFn >::clear(), PtexHashMap< KeyType, DataType, HashFn >::grow(), PtexHashMap< KeyType, DataType, HashFn >::iterator::operator++(), and PtexHashMap< KeyType, DataType, HashFn >::operator[]().

template<typename KeyType, typename DataType, typename HashFn>

int PtexHashMap< KeyType, DataType, HashFn >::_numEntries
| private

Definition at line 216 of file PtexHashMap.h.

Referenced by PtexHashMap< KeyType, DataType, HashFn >::clear(), PtexHashMap< KeyType, DataType, HashFn >::erase(), PtexHashMap< KeyType, DataType, HashFn >::operator[](), and PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher >::size().

template<typename KeyType, typename DataType, typename HashFn>

HashFn PtexHashMap< KeyType, DataType, HashFn >::hash
| private

Definition at line 220 of file PtexHashMap.h.

Referenced by PtexHashMap< KeyType, DataType, HashFn >::find(), PtexHashMap< KeyType, DataType, HashFn >::grow(), PtexHashMap< ReductionKey, FaceData *, ReductionKey::Hasher >::locate(), and PtexHashMap< KeyType, DataType, HashFn >::operator[]().

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

- PtexHashMap.h