neo::core::HashTable< Key, T, Cmp > Class Template Reference

#include <core/hashtable.h>

Collaboration diagram for neo::core::HashTable< Key, T, Cmp >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class Key, class T, class Cmp = Comparator< Key, Key >>
class neo::core::HashTable< Key, T, Cmp >

Hash table storing objects of template type. This is a container type, no automatic deallocation of objects will be done internally.

Author:
Mattias Jansson (mattias@realityrift.com)


Public Types

typedef HashTableIterator<
Key, T, Cmp > 
iterator
 Iterator, sequential.
typedef const iterator const_iterator
 Const iterator, sequential.

Public Member Functions

 HashTable (size_type size=7)
 Allocate storage and initialize hash table.
 HashTable (const HashTable< Key, T, Cmp > &table)
 Duplicate hash table.
virtual ~HashTable ()
 Deallocate storage.
iterator insert (const Key &key, const T &data)
 Add key/value pair.
void erase (const Key &key)
 Remove key.
void erase (const Key &key, const T &data)
 Remove key.
void erase (const const_iterator &iter)
 Remove element.
void eraseAll (const T &data, Array< Key > *p_keys=0)
 Remove keys with matching data.
iterator find (const Key &key, unsigned int hash=0)
 Find value for key.
const_iterator find (const Key &key, unsigned int hash=0) const
 Find value for key.
const T & findRaw (const Key &key, unsigned int hash, const T &null) const
 Find value for key.
const_iterator findKey (const T &data, const const_iterator &last=const_iterator()) const
 Reverse lookup.
iterator begin ()
 Get iterator of first object.
const_iterator begin () const
 Get iterator of first object.
iterator end ()
 Get iterator of first invalid object.
const_iterator end () const
 Get iterator of first invalid object.
size_type size () const
 Get number of objects.
void clear ()
 Clear all keys.
void swap (HashTable< Key, T, Cmp > &table)
 Swap hashtables.
T & operator[] (const Key &key)
 Access element by key.
HashTable< Key, T, Cmp > & operator= (const HashTable< Key, T, Cmp > &table)
 Assign hash table.
void getMinMaxBucketSize (size_type *p_min, size_type *p_max)
 Get min/max bucket size.
size_type getNumBuckets () const
 Get number of buckets.


Constructor & Destructor Documentation

template<class Key, class T, class Cmp>
neo::core::HashTable< Key, T, Cmp >::HashTable ( size_type  size = 7  ) 

Allocate and initialize hash table with the specified number of buckets

Parameters:
size Number of buckets

template<class Key, class T, class Cmp>
neo::core::HashTable< Key, T, Cmp >::HashTable ( const HashTable< Key, T, Cmp > &  table  ) 

Duplicate hash table

Parameters:
table hashtable to duplicate

template<class Key, class T, class Cmp>
neo::core::HashTable< Key, T, Cmp >::~HashTable (  )  [virtual]

Deallocate storage


Member Function Documentation

template<class Key, class T, class Cmp>
HashTable< Key, T, Cmp >::iterator neo::core::HashTable< Key, T, Cmp >::insert ( const Key &  key,
const T &  data 
) [inline]

Add key value into hash table. The data will replace any value with the same key previously stored in the table

Parameters:
key Key name
data Value
Returns:
Iterator for the stored key/value pair

template<class Key, class T, class Cmp>
void neo::core::HashTable< Key, T, Cmp >::erase ( const Key &  key  )  [inline]

Remove key from hash table and destruct associated object

Parameters:
key Key name

template<class Key, class T, class Cmp>
void neo::core::HashTable< Key, T, Cmp >::erase ( const Key &  key,
const T &  data 
) [inline]

Remove key from hash table and destruct associated object if matching given reference value

Parameters:
key Key name
data Value to remove, key/value pair will only be removed if value match

template<class Key, class T, class Cmp>
void neo::core::HashTable< Key, T, Cmp >::erase ( const const_iterator iter  )  [inline]

Remove element by iterator from table and destruct associated object

Parameters:
iter Iterator for element

template<class Key, class T, class Cmp>
void neo::core::HashTable< Key, T, Cmp >::eraseAll ( const T &  data,
Array< Key > *  p_keys = 0 
) [inline]

Remove all keys and destruct associated object if object matches given reference value

Parameters:
data Data to remove
p_keys Optional pointer to array receiving keys for removed data entries

template<class Key, class T, class Cmp>
HashTable< Key, T, Cmp >::iterator neo::core::HashTable< Key, T, Cmp >::find ( const Key &  key,
unsigned int  hash = 0 
) [inline]

Find value for key with optional precalculated hash value

Parameters:
key Key name
hash Hash value (zero if not precalculated)
Returns:
Iterator for element, end() if not found

template<class Key, class T, class Cmp>
const HashTable< Key, T, Cmp >::iterator neo::core::HashTable< Key, T, Cmp >::find ( const Key &  key,
unsigned int  hash = 0 
) const [inline]

Find value for key with optional precalculated hash value

Parameters:
key Key name
hash Hash value (zero if not precalculated)
Returns:
Iterator for element, end() if not found

template<class Key, class T, class Cmp>
const T & neo::core::HashTable< Key, T, Cmp >::findRaw ( const Key &  key,
unsigned int  hash,
const T &  null 
) const [inline]

Find value for key with optional precalculated hash value

Parameters:
key Key name
hash Hash value (zero if not precalculated)
null Value to return if not found
Returns:
Found value for key

template<class Key, class T, class Cmp>
const HashTable< Key, T, Cmp >::iterator neo::core::HashTable< Key, T, Cmp >::findKey ( const T &  data,
const const_iterator last = const_iterator() 
) const

Reverse lookup. Find first key with data matching given search data. If a last found key element is given, search wíll begin for next key after last found key.

Parameters:
data Value to search for
last Last found element
Returns:
Iterator to next element with value matching given data

template<class Key, class T, class Cmp>
HashTable< Key, T, Cmp >::iterator neo::core::HashTable< Key, T, Cmp >::begin (  )  [inline]

Get iterator of first object (pointer to first object)

Returns:
Iterator for (pointer to) first object

template<class Key, class T, class Cmp>
const HashTable< Key, T, Cmp >::iterator neo::core::HashTable< Key, T, Cmp >::begin (  )  const [inline]

Get iterator of first object (pointer to first object)

Returns:
Iterator for (pointer to) first object

template<class Key, class T, class Cmp>
HashTable< Key, T, Cmp >::iterator neo::core::HashTable< Key, T, Cmp >::end (  )  [inline]

Get iterator of first invalid object (pointer to object after last object)

Returns:
Iterator for (pointer to) object after last valid object

template<class Key, class T, class Cmp>
const HashTable< Key, T, Cmp >::iterator neo::core::HashTable< Key, T, Cmp >::end (  )  const [inline]

Get iterator of first invalid object (pointer to object after last object)

Returns:
Iterator for (pointer to) object after last valid object

template<class Key, class T, class Cmp>
HashTable< Key, T, Cmp >::size_type neo::core::HashTable< Key, T, Cmp >::size (  )  const [inline]

Get number of objects stored in hash table

Returns:
Number of stored objects

template<class Key, class T, class Cmp>
void neo::core::HashTable< Key, T, Cmp >::clear (  )  [inline]

Clear whole hashtable

template<class Key, class T, class Cmp>
void neo::core::HashTable< Key, T, Cmp >::swap ( HashTable< Key, T, Cmp > &  table  )  [inline]

Swap contents of two hashtables

Parameters:
table Hashtable to swap contents with

template<class Key, class T, class Cmp>
T & neo::core::HashTable< Key, T, Cmp >::operator[] ( const Key &  key  )  [inline]

Access the data element by key. If no value was previously associated with key a new key-value pair with default data is associated with the key and inserted in the table.

Parameters:
key Key
Returns:
Value

template<class Key, class T, class Cmp>
HashTable< Key, T, Cmp > & neo::core::HashTable< Key, T, Cmp >::operator= ( const HashTable< Key, T, Cmp > &  table  ) 

Assign hash table from reference

Parameters:
table Hashtable to copy values from
Returns:
Self-reference


The documentation for this class was generated from the following file:
Generated on Sat Feb 17 20:51:02 2007 for NeoEngine 2 - Evolution by  doxygen 1.5.1