Torque2D Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | List of all members
HashTable< Key, Value > Class Template Reference

`#include <hashTable.h>`

Inheritance diagram for HashTable< Key, Value >:

## Classes
class | _Iterator
struct | Pair

## Public Types
typedef Pair | ValueType
typedef Pair & | Reference
typedef const Pair & | ConstReference
typedef S32 | DifferenceType
typedef U32 | SizeType
typedef _Iterator< Pair, Node, HashTable > | iterator
typedef _Iterator< const Pair, const Node, const HashTable > | const_iterator

## Public Member Functions
| HashTable ()
| ~HashTable ()
| HashTable (const HashTable &p)
U32 | size () const
| Return the number of elements. More...
U32 | tableSize () const
| Return the size of the hash bucket table. More...
void | clear ()
| Empty the HashTable. More...
void | resize (U32 size)
bool | isEmpty () const
| Returns true if the table is empty. More...
F32 | collisions () const
| Returns the average number of nodes per bucket. More...
iterator | insertEqual (const Key &key, const Value &)
iterator | insertUnique (const Key &key, const Value &)
void | erase (iterator)
| Erase the given entry. More...
void | erase (const Key &key)
| Erase all matching keys from the table. More...
iterator | findOrInsert (const Key &key)
iterator | find (const Key &)
| Find the first entry for the given key. More...
const_iterator | find (const Key &) const
| Find the first entry for the given key. More...
S32 | count (const Key &)
| Count the number of matching keys in the table. More...
iterator | begin ()
| iterator to first element More...
const_iterator | begin () const
| iterator to first element More...
iterator | end ()
| iterator to last element + 1 More...
const_iterator | end () const
| iterator to last element + 1 More...
void | operator= (const HashTable &p)

## Detailed Description

### template<typename Key, typename Value>
class HashTable< Key, Value >

A HashTable template class.

The hash table class maps between a key and an associated value. Access using the key is performed using a hash table. The class provides methods for both unique and equal keys. The global ::hash(Type) function is used for hashing, see util/hash.h

## Member Typedef Documentation

typedef _Iterator<const Pair,const Node,const HashTable> const_iterator

typedef const Pair& ConstReference

typedef S32 DifferenceType

typedef _Iterator<Pair,Node,HashTable> iterator

typedef Pair& Reference

typedef U32 SizeType

typedef Pair ValueType

## Constructor & Destructor Documentation

HashTable | ( |  | ) |

~HashTable | ( |  | ) |

HashTable | ( | const HashTable< Key, Value > & | p | ) |

## Member Function Documentation

HashTable< Key, Value >::iterator begin | ( |  | ) |
| inline

iterator to first element

HashTable< Key, Value >::const_iterator begin | ( |  | ) | const
| inline

iterator to first element

void clear | ( |  | ) |
| inline

Empty the HashTable.

F32 collisions | ( |  | ) | const
| inline

Returns the average number of nodes per bucket.

S32 count | ( | const Key & | key | ) |

Count the number of matching keys in the table.

HashTable< Key, Value >::iterator end | ( | void |  | ) |
| inline

iterator to last element + 1

HashTable< Key, Value >::const_iterator end | ( | void |  | ) | const
| inline

iterator to last element + 1

void erase | ( | iterator | node | ) |

Erase the given entry.

void erase | ( | const Key & | key | ) |

Erase all matching keys from the table.

HashTable< Key, Value >::iterator find | ( | const Key & | key | ) |

Find the first entry for the given key.

const_iterator find | ( | const Key & |  | ) | const

Find the first entry for the given key.

HashTable< Key, Value >::iterator findOrInsert | ( | const Key & | key | ) |

Find the key, or insert a one if it doesn't exist. Returns the first key in the table that matches, or inserts one if there are none.

HashTable< Key, Value >::iterator insertEqual | ( | const Key & | key,
|  | const Value & | x
| ) |  |

Insert the key value pair and allow duplicates. This insert method allows duplicate keys. Keys are grouped together but are not sorted.

HashTable< Key, Value >::iterator insertUnique | ( | const Key & | key,
|  | const Value & | x
| ) |  |

Insert the key value pair but don't insert duplicates. This insert method does not insert duplicate keys. If the key already exists in the table the function will fail and end() is returned.

bool isEmpty | ( |  | ) | const
| inline

Returns true if the table is empty.

void operator= | ( | const HashTable< Key, Value > & | p | ) |

void resize | ( | U32 | size | ) |
| inline

Resize the bucket table for an estimated number of elements. This method will optimize the hash bucket table size to hold the given number of elements. The size argument is a hint, and will not be the exact size of the table. If the table is sized down below it's optimal size, the next insert will cause it to be resized again. Normally this function is used to avoid resizes when the number of elements that will be inserted is known in advance.

U32 size | ( |  | ) | const
| inline

Return the number of elements.

U32 tableSize | ( |  | ) | const
| inline

Return the size of the hash bucket table.

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

- collection/hashTable.h