Main Page | Modules | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

HashMap< Key, T > Class Template Reference
[Generic Hash Associative Containers]

Generic Hash Map Class. More...

#include <hashMap.h>

List of all members.

Public Types

typedef ::std::pair< Key, T > ValueType
typedef Key KeyType
typedef ::std::pair< Key,
T > * 
PointerType
typedef Node * IteratorPosition
Type definitions
typedef ForwardIterator< HashMap<
Key, T >, ValueType, PointerType,
IteratorTraits_ > 
Iterator
typedef ConstForwardIterator<
HashMap< Key, T >, ValueType,
PointerType, IteratorTraits_ > 
ConstIterator
Enums and Constants
enum  { INITIAL_CAPACITY = 4, INITIAL_NUMBER_OF_BUCKETS = 3 }

Public Member Functions

Iterator begin () throw ()
Iterator end () throw ()
ConstIterator begin () const throw ()
ConstIterator end () const throw ()
Constructors and Destructors
 HashMap (Size initial_capacity=INITIAL_CAPACITY, Size number_of_buckets=INITIAL_NUMBER_OF_BUCKETS) throw ()
 Default constructor.
 HashMap (const HashMap &hash_map) throw ()
 Copy Constructor.
virtual ~HashMap () throw ()
 Destructor.
virtual void clear () throw ()
 Clear the hash map.
void destroy () throw ()
 Clear the hash map.
Assignment
void set (const HashMap &hash_map) throw ()
 Assignment from another hash map.
const HashMapoperator= (const HashMap &hash_map) throw ()
 Assignment operator.
void get (HashMap &hash_map) const throw ()
 Assign the contents of this hash map to another map.
void swap (HashMap &hash_map) throw ()
 Swap the contents of two hash maps.
Accessors
Size getBucketSize () const throw ()
 Return the number of buckets.
Size getCapacity () const throw ()
 Return the capcacity of the hash map.
Size getSize () const throw ()
 Return the number of entries in the map.
Size size () const throw ()
 Return the number of entries in the map.
Iterator find (const Key &key) throw ()
 Find the element whose key is key.
ConstIterator find (const Key &key) const throw ()
 Find the element whose key is key.
T & operator[] (const Key &key) throw ()
 Return a mutable reference to the element whose key is key.
const T & operator[] (const Key &key) const throw (typename HashMap<Key, T>::IllegalKey)
 Return a constant reference to the element whose key is key.
::std::pair< Iterator, bool > insert (const ValueType &entry) throw ()
 Insert a new entry into the hash map.
Iterator insert (Iterator pos, const ValueType &entry) throw ()
 Insert a new entry into the hash map.
Size erase (const Key &key) throw ()
 Erase element with key key.
void erase (Iterator pos) throw (Exception::IncompatibleIterators, Exception::InvalidIterator)
 Erase element at a given position.
void erase (Iterator first, Iterator last) throw (Exception::IncompatibleIterators)
 Erase a range of elements.
Miscellaneous
void host (Visitor< HashMap< Key, T > > &visitor) throw ()
 Host a visitor for all map entries.
Predicates
bool has (const Key &key) const throw ()
 Test whether the map contains the given key.
bool isEmpty () const throw ()
 Test whether the map is empty.
bool operator== (const HashMap &hash_map) const throw ()
 Compare two hash maps.
bool operator!= (const HashMap &hash_map) const throw ()
 Compare two hash maps.
Debugging and Diagnostics
bool isValid () const throw ()
 Return true if the hash map is consistent.
virtual void dump (::std::ostream &s=::std::cout, Size depth=0) const throw ()
 Dump the constent of this instance to an ostream.
Iternal iterators
bool apply (UnaryProcessor< ValueType > &processor) throw ()
 Apply a processor to the hashmap.

Protected Member Functions

virtual Node * newNode_ (const ValueType &value, Node *next) const throw ()
virtual void deleteNode_ (Node *node) const throw ()
virtual HashIndex hash (const Key &key) const throw ()
virtual bool needRehashing_ () const throw ()
virtual void rehash () throw ()
void deleteBuckets_ () throw ()
HashIndex hash_ (const Key &key) const throw ()
void rehash_ () throw ()

Protected Attributes

Attributes
Size size_
 The number of entries in the map.
Size capacity_
 The maximum number of entries before a resize operation is required.
vector< Node * > bucket_
 Buckets are stored as a vector of linked lists of Nodes.

Friends

class IteratorTraits_


Detailed Description

template<class Key, class T>
class HashMap< Key, T >

Generic Hash Map Class.


Member Enumeration Documentation

template<class Key, class T>
anonymous enum
 

Enumeration values:
INITIAL_CAPACITY  Initial capacity of the empty hash map.
INITIAL_NUMBER_OF_BUCKETS  Initial number of buckets of the empty hash map.


Constructor & Destructor Documentation

template<class Key, class T>
HashMap< Key, T >::HashMap Size  initial_capacity = INITIAL_CAPACITY,
Size  number_of_buckets = INITIAL_NUMBER_OF_BUCKETS
throw ()
 

Default constructor.

Create a new and empty hash map.

Parameters:
initial_capacity the capacity of the hash map
number_of_buckets the number of buckets to create

template<class Key, class T>
HashMap< Key, T >::HashMap const HashMap< Key, T > &  hash_map  )  throw ()
 

Copy Constructor.

template<class Key, class T>
virtual HashMap< Key, T >::~HashMap  )  throw () [virtual]
 

Destructor.


Member Function Documentation

template<class Key, class T>
bool HashMap< Key, T >::apply UnaryProcessor< ValueType > &  processor  )  throw ()
 

Apply a processor to the hashmap.

Returns:
true if the processor could be applied.

template<class Key, class T>
void HashMap< Key, T >::clear  )  throw () [virtual]
 

Clear the hash map.

Remove all nodes from all buckets. The capacity and the number of buckets remain unchanged.

Reimplemented in Options.

template<class Key, class T>
void HashMap< Key, T >::destroy  )  throw ()
 

Clear the hash map.

Remove all nodes from all buckets. The capacity and the number of buckets remain unchanged. Simply calls clear.

Reimplemented in StringHashMap< Value >, StringHashMap< list< Position > >, StringHashMap< NameMap >, StringHashMap< JCAMPValue >, StringHashMap< Position >, StringHashMap< Atom::Type >, StringHashMap< Ring >, StringHashMap< CreateMethod >, StringHashMap< Index >, StringHashMap< List< String >::Iterator >, StringHashMap< float >, StringHashMap< RuleList >, StringHashMap< Vector3 >, StringHashMap< String >, StringHashMap< SectionIterator >, StringHashMap< vector< Position > >, StringHashMap< vector< Data > >, StringHashMap< CreationMethod >, StringHashMap< EmbeddableVector >, StringHashMap< block >, and StringHashMap< ColorRGBA >.

template<class Key, class T>
void HashMap< Key, T >::dump ::std::ostream &  s = ::std::cout,
Size  depth = 0
const throw () [virtual]
 

Dump the constent of this instance to an ostream.

template<class Key, class T>
void HashMap< Key, T >::erase Iterator  first,
Iterator  last
throw (Exception::IncompatibleIterators)
 

Erase a range of elements.

Erase all elements in the range first - last.

template<class Key, class T>
void HashMap< Key, T >::erase Iterator  pos  )  throw (Exception::IncompatibleIterators, Exception::InvalidIterator)
 

Erase element at a given position.

Parameters:
pos an iterator pointing to the element to delete

template<class Key, class T>
Size HashMap< Key, T >::erase const Key &  key  )  throw ()
 

Erase element with key key.

Returns:
Size the number of elements erased (0 or 1)

template<class Key, class T>
HashMap< Key, T >::ConstIterator HashMap< Key, T >::find const Key &  key  )  const throw ()
 

Find the element whose key is key.

template<class Key, class T>
HashMap< Key, T >::Iterator HashMap< Key, T >::find const Key &  key  )  throw ()
 

Find the element whose key is key.

template<class Key, class T>
void HashMap< Key, T >::get HashMap< Key, T > &  hash_map  )  const throw ()
 

Assign the contents of this hash map to another map.

template<class Key, class T>
Size HashMap< Key, T >::getCapacity  )  const throw ()
 

Return the capcacity of the hash map.

template<class Key, class T>
Size HashMap< Key, T >::getSize  )  const throw ()
 

Return the number of entries in the map.

Reimplemented in StringHashMap< Value >, StringHashMap< list< Position > >, StringHashMap< NameMap >, StringHashMap< JCAMPValue >, StringHashMap< Position >, StringHashMap< Atom::Type >, StringHashMap< Ring >, StringHashMap< CreateMethod >, StringHashMap< Index >, StringHashMap< List< String >::Iterator >, StringHashMap< float >, StringHashMap< RuleList >, StringHashMap< Vector3 >, StringHashMap< String >, StringHashMap< SectionIterator >, StringHashMap< vector< Position > >, StringHashMap< vector< Data > >, StringHashMap< CreationMethod >, StringHashMap< EmbeddableVector >, StringHashMap< block >, and StringHashMap< ColorRGBA >.

template<class Key, class T>
bool HashMap< Key, T >::has const Key &  key  )  const throw ()
 

Test whether the map contains the given key.

Reimplemented in StringHashMap< Value >, StringHashMap< list< Position > >, StringHashMap< NameMap >, StringHashMap< JCAMPValue >, StringHashMap< Position >, StringHashMap< Atom::Type >, StringHashMap< Ring >, StringHashMap< CreateMethod >, StringHashMap< Index >, StringHashMap< List< String >::Iterator >, StringHashMap< float >, StringHashMap< RuleList >, StringHashMap< Vector3 >, StringHashMap< String >, StringHashMap< SectionIterator >, StringHashMap< vector< Position > >, StringHashMap< vector< Data > >, StringHashMap< CreationMethod >, StringHashMap< EmbeddableVector >, StringHashMap< block >, and StringHashMap< ColorRGBA >.

template<class Key, class T>
void HashMap< Key, T >::host Visitor< HashMap< Key, T > > &  visitor  )  throw ()
 

Host a visitor for all map entries.

template<class Key, class T>
HashMap< Key, T >::Iterator HashMap< Key, T >::insert Iterator  pos,
const ValueType &  entry
throw ()
 

Insert a new entry into the hash map.

For STL compatibility. The value of pos is ignored.

template<class Key, class T>
std::pair< typename HashMap< Key, T >::Iterator, bool > HashMap< Key, T >::insert const ValueType &  entry  )  throw ()
 

Insert a new entry into the hash map.

Reimplemented in StringHashMap< Value >, StringHashMap< list< Position > >, StringHashMap< NameMap >, StringHashMap< JCAMPValue >, StringHashMap< Position >, StringHashMap< Atom::Type >, StringHashMap< Ring >, StringHashMap< CreateMethod >, StringHashMap< Index >, StringHashMap< List< String >::Iterator >, StringHashMap< float >, StringHashMap< RuleList >, StringHashMap< Vector3 >, StringHashMap< String >, StringHashMap< SectionIterator >, StringHashMap< vector< Position > >, StringHashMap< vector< Data > >, StringHashMap< CreationMethod >, StringHashMap< EmbeddableVector >, StringHashMap< block >, and StringHashMap< ColorRGBA >.

template<class Key, class T>
bool HashMap< Key, T >::isEmpty  )  const throw ()
 

Test whether the map is empty.

Reimplemented in StringHashMap< Value >, StringHashMap< list< Position > >, StringHashMap< NameMap >, StringHashMap< JCAMPValue >, StringHashMap< Position >, StringHashMap< Atom::Type >, StringHashMap< Ring >, StringHashMap< CreateMethod >, StringHashMap< Index >, StringHashMap< List< String >::Iterator >, StringHashMap< float >, StringHashMap< RuleList >, StringHashMap< Vector3 >, StringHashMap< String >, StringHashMap< SectionIterator >, StringHashMap< vector< Position > >, StringHashMap< vector< Data > >, StringHashMap< CreationMethod >, StringHashMap< EmbeddableVector >, StringHashMap< block >, and StringHashMap< ColorRGBA >.

template<class Key, class T>
bool HashMap< Key, T >::isValid  )  const throw ()
 

Return true if the hash map is consistent.

Condition: the number of entries in all buckets has to be equal the stored number of entries (getSize()).

template<class Key, class T>
bool HashMap< Key, T >::operator!= const HashMap< Key, T > &  hash_map  )  const throw ()
 

Compare two hash maps.

template<class Key, class T>
const HashMap< Key, T > & HashMap< Key, T >::operator= const HashMap< Key, T > &  hash_map  )  throw ()
 

Assignment operator.

Assign the contents of a hash map to another.

Parameters:
hash_map the hash map to assign from

template<class Key, class T>
bool HashMap< Key, T >::operator== const HashMap< Key, T > &  hash_map  )  const throw ()
 

Compare two hash maps.

template<class Key, class T>
const T & HashMap< Key, T >::operator[] const Key &  key  )  const throw (typename HashMap<Key, T>::IllegalKey)
 

Return a constant reference to the element whose key is key.

Exceptions:
IllegalKey if the given key does not exist
Parameters:
key the key

template<class Key, class T>
T & HashMap< Key, T >::operator[] const Key &  key  )  throw ()
 

Return a mutable reference to the element whose key is key.

If an element with the key key does not exist, it is inserted.

Parameters:
key the key

template<class Key, class T>
void HashMap< Key, T >::set const HashMap< Key, T > &  hash_map  )  throw ()
 

Assignment from another hash map.

Parameters:
hash_map the hash map to assign from

template<class Key, class T>
Size HashMap< Key, T >::size  )  const throw ()
 

Return the number of entries in the map.

template<class Key, class T>
void HashMap< Key, T >::swap HashMap< Key, T > &  hash_map  )  throw ()
 

Swap the contents of two hash maps.