GaudiUtils::HashMap< K, T, H, M > Class Template Reference

Common class providing an architecture-independent hash map. More...

#include <GaudiKernel/HashMap.h>

Inheritance diagram for GaudiUtils::HashMap< K, T, H, M >:
Collaboration diagram for GaudiUtils::HashMap< K, T, H, M >:

Public Types

typedef H hasher
 
typedef H hasher
 
- Public Types inherited from GaudiUtils::Map< K, T, M >
typedef M map_type
 
typedef K key_type
 
typedef T mapped_type
 
typedef K argument_type
 
typedef T result_type
 
typedef std::pair< const K, T > value_type
 
typedef map_type::size_type size_type
 
typedef map_type::iterator iterator
 
typedef map_type::const_iterator const_iterator
 
typedef M map_type
 
typedef K key_type
 
typedef T mapped_type
 
typedef K argument_type
 
typedef T result_type
 
typedef std::pair< const K, T > value_type
 
typedef map_type::size_type size_type
 
typedef map_type::iterator iterator
 
typedef map_type::const_iterator const_iterator
 

Public Member Functions

hasher hash_funct () const
 
hasher hash_funct () const
 
- Public Member Functions inherited from GaudiUtils::Map< K, T, M >
 Map ()
 Standard constructor. More...
 
 Map (const map_type &other)
 Constructor from a standard map. More...
 
template<typename In >
 Map (In first, In last)
 Construct from a subset. More...
 
virtual ~Map ()
 Virtual destructor. You can inherit from this map type. More...
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
mapped_typeoperator[] (const key_type &key)
 
iterator find (const key_type &key)
 
const_iterator find (const key_type &key) const
 
size_type count (const key_type &key) const
 
iterator lower_bound (const key_type &key)
 
const_iterator lower_bound (const key_type &key) const
 
iterator upper_bound (const key_type &key)
 
const_iterator upper_bound (const key_type &key) const
 
std::pair< iterator, iteratorequal_range (const key_type &key)
 
std::pair< const_iterator, const_iteratorequal_range (const key_type &key) const
 
std::pair< iterator, bool > insert (const value_type &val)
 
std::pair< iterator, bool > insert (const key_type &key, const mapped_type &val)
 
template<typename In >
void insert (In first, In last)
 
iterator insert (iterator, const value_type &val)
 
void erase (iterator pos)
 
size_type erase (const key_type &key)
 
void erase (iterator first, iterator last)
 
void clear ()
 
size_type size () const
 
size_type max_size () const
 
bool empty () const
 
void swap (map_type &other)
 
const result_typeoperator() (const argument_type &key) const
 Allow to use Map as an unary function. More...
 
const mapped_typeoperator[] (const key_type &key) const
 Access elements of a const Map. More...
 
const result_typeat (const argument_type &key) const
 checked access to the map

Exceptions
std::out_of_rangefor missing keys
More...
 
Mapmerge (const map_type &other)
 Merge two maps. More...
 
Mapmerge (const Map &other)
 Merge two maps. More...
 
template<class K1 , class K2 , class K3 >
Mapmerge (const Map< K1, K2, K3 > &other)
 Merge two maps. More...
 
void update (const key_type &key, const mapped_type &mapped)
 
 operator map_type & ()
 Allows to use the Map wherever an std::map is explicitly requested. More...
 
 operator const map_type & () const
 
const key_typekey_at (const size_type index) const
 useful method for python decoration: More...
 
const mapped_typevalue_at (const size_type index) const
 useful method for python decoration: More...
 
 Map ()
 Standard constructor. More...
 
 Map (const map_type &other)
 Constructor from a standard map. More...
 
template<typename In >
 Map (In first, In last)
 Construct from a subset. More...
 
virtual ~Map ()
 Virtual destructor. You can inherit from this map type. More...
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
mapped_typeoperator[] (const key_type &key)
 
iterator find (const key_type &key)
 
const_iterator find (const key_type &key) const
 
size_type count (const key_type &key) const
 
iterator lower_bound (const key_type &key)
 
const_iterator lower_bound (const key_type &key) const
 
iterator upper_bound (const key_type &key)
 
const_iterator upper_bound (const key_type &key) const
 
std::pair< iterator, iteratorequal_range (const key_type &key)
 
std::pair< const_iterator, const_iteratorequal_range (const key_type &key) const
 
std::pair< iterator, bool > insert (const value_type &val)
 
std::pair< iterator, bool > insert (const key_type &key, const mapped_type &val)
 
template<typename In >
void insert (In first, In last)
 
iterator insert (iterator, const value_type &val)
 
void erase (iterator pos)
 
size_type erase (const key_type &key)
 
void erase (iterator first, iterator last)
 
void clear ()
 
size_type size () const
 
size_type max_size () const
 
bool empty () const
 
void swap (map_type &other)
 
const result_typeoperator() (const argument_type &key) const
 Allow to use Map as an unary function. More...
 
const mapped_typeoperator[] (const key_type &key) const
 Access elements of a const Map. More...
 
const result_typeat (const argument_type &key) const
 checked access to the map

Exceptions
std::out_of_rangefor missing keys
More...
 
Mapmerge (const map_type &other)
 Merge two maps. More...
 
Mapmerge (const Map &other)
 Merge two maps. More...
 
template<class K1 , class K2 , class K3 >
Mapmerge (const Map< K1, K2, K3 > &other)
 Merge two maps. More...
 
void update (const key_type &key, const mapped_type &mapped)
 
 operator map_type & ()
 Allows to use the Map wherever an std::map is explicitly requested. More...
 
 operator const map_type & () const
 
const key_typekey_at (const size_type index) const
 useful method for python decoration: More...
 
const mapped_typevalue_at (const size_type index) const
 useful method for python decoration: More...
 
- Public Member Functions inherited from Gaudi::Utils::MapBase
virtual ~MapBase ()
 virtual destructor More...
 
virtual ~MapBase ()
 virtual destructor More...
 

Additional Inherited Members

- Protected Member Functions inherited from Gaudi::Utils::MapBase
void throw_out_of_range_exception () const
 throw std::out_of_range exception More...
 
void throw_out_of_range_exception () const
 throw std::out_of_range exception More...
 
- Protected Attributes inherited from GaudiUtils::Map< K, T, M >
map_type m_map
 
- Static Protected Attributes inherited from GaudiUtils::Map< K, T, M >
static const result_type s_null_value = typename Map<K,T,M>::result_type()
 

Detailed Description

template<typename K, typename T, typename H = Hash<K>, typename M = __gnu_cxx::hash_map<K,T,H>>
class GaudiUtils::HashMap< K, T, H, M >

Common class providing an architecture-independent hash map.

Due to helper base class Gaudi::Utils::MapBase, this class is "python-friendly", and one can perform all python manipulaitons in intuitive way:

>>> m = ... ## get the map
>>> print m ## print the map a'la python class dict
...
>>> for key in m : print key, m[key] ## iteration over the map
...
>>> for key,value in m.iteritems() : print key, value
...
>>> keys = m.keys() ## get the list of keys
>>> values = m.values () ## get the list of values
>> items = m.items () ## get the list of items
>>> if 'one' in m ## check the presence of the key in map
>>> v = m.get(key', None) ## return m[key] for existing key, else None
>>> del m[key] ## erase the key form the map
>>> value m[key] ## unchecked access through the key
...
>>> m.update( key, value ) ## update/insert key/value pair
Attention
One needs to redfine __setitem__ and __getitem__ methods in python:
>>> type(m).__setitem__ = Gaudi.Utils.MapBase.__setitem__
>>> type(m).__getitem__ = Gaudi.Utils.MapBase.__getitem__
>>> m[key] = value ## much more intuitive semantics for key insertion

In a similar way __delitem__ methods can be redefined.

Warning
To bypass some compilation problme (and to avoid the unnesessary expansion of dictionaries) it is nesessary to exclude from dictionary the following methods:
  • lower_bound
  • upper_bound
  • equal_range
  • insert
See also
Gaudi::Utils::MapBase
Author
Marco Clemencic
Date
2005-10-06

Definition at line 108 of file HashMap.h.

Member Typedef Documentation

template<typename K, typename T, typename H = Hash<K>, typename M = __gnu_cxx::hash_map<K,T,H>>
typedef H GaudiUtils::HashMap< K, T, H, M >::hasher

Definition at line 111 of file HashMap.h.

template<typename K, typename T, typename H = Hash<K>, typename M = __gnu_cxx::hash_map<K,T,H>>
typedef H GaudiUtils::HashMap< K, T, H, M >::hasher

Definition at line 111 of file HashMap.h.

Member Function Documentation

template<typename K, typename T, typename H = Hash<K>, typename M = __gnu_cxx::hash_map<K,T,H>>
hasher GaudiUtils::HashMap< K, T, H, M >::hash_funct ( ) const
inline

Definition at line 113 of file HashMap.h.

113  {
114 // Marco Cl.: since on windows we are using a std::map, we have to provide a different implementation
115 // for GaudiUtils::HashMap::hash_funct(). (std::map::hash_funct does not exist)
116 #ifdef _WIN32
117  return hasher();
118 #else
119  return this->m_map.hash_funct();
120 #endif
121  }
map_type m_map
Definition: Map.h:105
template<typename K, typename T, typename H = Hash<K>, typename M = __gnu_cxx::hash_map<K,T,H>>
hasher GaudiUtils::HashMap< K, T, H, M >::hash_funct ( ) const
inline

Definition at line 113 of file HashMap.h.

113  {
114 // Marco Cl.: since on windows we are using a std::map, we have to provide a different implementation
115 // for GaudiUtils::HashMap::hash_funct(). (std::map::hash_funct does not exist)
116 #ifdef _WIN32
117  return hasher();
118 #else
119  return this->m_map.hash_funct();
120 #endif
121  }
map_type m_map
Definition: Map.h:105

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