Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

HashMap Class Template Reference
[Datastructures]

#include <OpenMS/DATASTRUCTURES/HashMap.h>

List of all members.


Detailed Description

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

Generic Hash Map Class.

This class implements a simple hash map using hashing by chaining.

Public Types

typedef std::pair< Key, T > ValueType
typedef Key KeyType
typedef std::pair< Key, T > * PointerType
typedef std::reverse_iterator
< Iterator
ReverseIterator
typedef std::reverse_iterator
< ConstIterator
ConstReverseIterator
Enums and Constants
enum  { INITIAL_CAPACITY = 100, INITIAL_NUMBER_OF_BUCKETS = 50 }
STL-compliance type definitions
typedef ValueType value_type
typedef UInt size_type
typedef Int difference_type
typedef ValueTypereference
typedef const ValueTypeconst_reference
typedef ValueTypepointer
typedef Iterator iterator
typedef ConstIterator const_iterator
typedef ReverseIterator reverse_iterator
typedef ConstReverseIterator const_reverse_iterator

Public Member Functions

Iterator begin () throw ()
Iterator end () throw ()
ConstIterator begin () const throw ()
ConstIterator end () const throw ()
Constructors and Destructors
 HashMap (UInt initial_capacity=INITIAL_CAPACITY, UInt number_of_buckets=INITIAL_NUMBER_OF_BUCKETS) throw ()
 HashMap (const HashMap &hash_map) throw ()
virtual ~HashMap () throw ()
virtual void clear () throw ()
void destroy () throw ()
Assignment
void set (const HashMap &hash_map) throw ()
const HashMapoperator= (const HashMap &hash_map) throw ()
void get (HashMap &hash_map) const throw ()
void swap (HashMap &hash_map) throw ()
Accessors
UInt getBucketSize () const throw ()
UInt getCapacity () const throw ()
UInt getSize () const throw ()
UInt size () const throw ()
Iterator find (const Key &key) throw ()
ConstIterator find (const Key &key) const throw ()
T & operator[] (const Key &key) throw ()
const T & operator[] (const Key &key) const throw (typename HashMap<Key, T>::IllegalKey)
std::pair< Iterator, bool > insert (const ValueType &entry) throw ()
Iterator insert (Iterator pos, const ValueType &entry) throw ()
UInt erase (const Key &key) throw ()
void erase (Iterator pos) throw ()
void erase (Iterator first, Iterator last) throw ()
Predicates
bool has (const Key &key) const throw ()
bool isEmpty () const throw ()
bool operator== (const HashMap &hash_map) const throw ()
bool operator!= (const HashMap &hash_map) const throw ()

Protected Member Functions

virtual NodenewNode_ (const ValueType &value, Node *next) const throw ()
virtual void deleteNode_ (Node *node) const throw ()
virtual UInt getHashKey_ (const Key &key) const throw ()
virtual bool needRehashing_ () const throw ()
virtual void recalculateCapacity_ () throw ()
PointerType find_ (const Key &key, UInt &index) throw ()
PointerType find_ (const Key &key, UInt &index) const throw ()
void deleteBuckets_ () throw ()
UInt hash_ (const Key &key) const throw ()
void rehash_ () throw ()

Protected Attributes

Attributes
UInt size_
UInt capacity_
std::vector< Node * > bucket_

Classes

class  ConstIterator
 HashMap const_iterator class. More...
class  IllegalKey
 HashMap illegal key exception. More...
class  Iterator
 HashMap iterator class. More...
struct  Node
 HashMap node (internal use only). More...


Member Typedef Documentation

typedef std::pair<Key, T> ValueType

typedef Key KeyType

typedef std::pair<Key, T>* PointerType

typedef std::reverse_iterator<Iterator> ReverseIterator

typedef std::reverse_iterator<ConstIterator> ConstReverseIterator

typedef ValueType value_type

typedef UInt size_type

typedef Int difference_type

typedef ValueType& reference

typedef const ValueType& const_reference

typedef ValueType& pointer

typedef Iterator iterator

typedef ConstIterator const_iterator

typedef ReverseIterator reverse_iterator

typedef ConstReverseIterator const_reverse_iterator


Member Enumeration Documentation

anonymous enum

Enumerator:
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

HashMap ( UInt  initial_capacity = INITIAL_CAPACITY,
UInt  number_of_buckets = INITIAL_NUMBER_OF_BUCKETS 
) throw () [inline]

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

HashMap ( const HashMap< Key, T > &  hash_map  )  throw () [inline]

Copy Constructor.

virtual ~HashMap (  )  throw () [inline, virtual]

Destructor.


Member Function Documentation

void clear (  )  throw () [inline, virtual]

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

void destroy (  )  throw () [inline]

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

void set ( const HashMap< Key, T > &  hash_map  )  throw () [inline]

Assignment from another hash map.

Parameters:
hash_map the hash map to assign from

const HashMap< Key, T > & operator= ( const HashMap< Key, T > &  hash_map  )  throw () [inline]

Assignment operator. Assign the contents of a hash map to another.

Parameters:
hash_map the hash map to assign from

void get ( HashMap< Key, T > &  hash_map  )  const throw () [inline]

Assign the contents of this hash map to another map.

void swap ( HashMap< Key, T > &  hash_map  )  throw () [inline]

Swap the contents of two hash maps.

UInt getBucketSize (  )  const throw () [inline]

Return the number of buckets

UInt getCapacity (  )  const throw () [inline]

Return the capcacity of the hash map.

UInt getSize (  )  const throw () [inline]

Return the number of entries in the map.

UInt size (  )  const throw () [inline]

Return the number of entries in the map.

Iterator find ( const Key &  key  )  throw () [inline]

Find the element whose key is key.

ConstIterator find ( const Key &  key  )  const throw () [inline]

Find the element whose key is key.

T & operator[] ( const Key &  key  )  throw () [inline]

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

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

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

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

std::pair< typename HashMap< Key, T >::Iterator, bool > insert ( const ValueType entry  )  throw () [inline]

Insert a new entry into the hash map.

Iterator insert ( Iterator  pos,
const ValueType entry 
) throw ()

Insert a new entry into the hash map. For STL compatibility. The value of pos is ignored.

UInt erase ( const Key &  key  )  throw () [inline]

Erase element with key key.

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

void erase ( Iterator  pos  )  throw () [inline]

Erase element at a given position.

Parameters:
pos an iterator pointing to the element to delete

void erase ( Iterator  first,
Iterator  last 
) throw () [inline]

Erase a range of elements. Erase all elements in the range first - last.

bool has ( const Key &  key  )  const throw () [inline]

Test whether the map contains the given key.

bool isEmpty (  )  const throw () [inline]

Test whether the map is empty.

bool operator== ( const HashMap< Key, T > &  hash_map  )  const throw () [inline]

Compare two hash maps.

bool operator!= ( const HashMap< Key, T > &  hash_map  )  const throw () [inline]

Compare two hash maps.

Iterator begin (  )  throw () [inline]

Iterator end (  )  throw () [inline]

ConstIterator begin (  )  const throw () [inline]

ConstIterator end (  )  const throw () [inline]

virtual Node* newNode_ ( const ValueType value,
Node next 
) const throw () [protected, virtual]

virtual void deleteNode_ ( Node node  )  const throw () [protected, virtual]

UInt getHashKey_ ( const Key &  key  )  const throw () [inline, protected, virtual]

bool needRehashing_ (  )  const throw () [inline, protected, virtual]

void recalculateCapacity_ (  )  throw () [inline, protected, virtual]

PointerType find_ ( const Key &  key,
UInt index 
) throw () [protected]

PointerType find_ ( const Key &  key,
UInt index 
) const throw () [protected]

void deleteBuckets_ (  )  throw () [inline, protected]

UInt hash_ ( const Key &  key  )  const throw () [inline, protected]

void rehash_ (  )  throw () [inline, protected]


Member Data Documentation

UInt size_ [protected]

The number of entries in the map

UInt capacity_ [protected]

The maximum number of entries before a resize operation is required

std::vector<Node*> bucket_ [protected]

Buckets are stored as a vector of linked lists of Nodes


The documentation for this class was generated from the following file:
Generated Tue Apr 1 15:36:43 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1