The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
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
 

Public Member Functions

hasher hash_funct () const
 

Friends

std::ostream & operator<< (std::ostream &s, const GaudiUtils::HashMap< K, T, H, M > &m)
 Serialize a GaudiUtils::HashMap in a python like format.
 

Detailed Description

template<typename K, typename T, typename H = Hash<K>, typename M = std::unordered_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
Helper base-class to allow the generic Python-decoration for all "map-like" classes in Gaudi.
Definition MapBase.h:45
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1

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 80 of file HashMap.h.

Member Typedef Documentation

◆ hasher

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

Definition at line 82 of file HashMap.h.

Member Function Documentation

◆ hash_funct()

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

Definition at line 83 of file HashMap.h.

83{ return this->m_map.hash_funct(); }
Common class providing an architecture-independent hash map.
Definition HashMap.h:80
hasher hash_funct() const
Definition HashMap.h:83

Friends And Related Symbol Documentation

◆ operator<<

template<typename K, typename T, typename H = Hash<K>, typename M = std::unordered_map<K, T, H>>
std::ostream & operator<< ( std::ostream & s,
const GaudiUtils::HashMap< K, T, H, M > & m )
friend

Serialize a GaudiUtils::HashMap in a python like format.

E.g. "{a: 1, b: 2}". This implementation is not efficient, but very simple. Anyway a print-out of a hash map is not something that we do every second.

Definition at line 88 of file HashMap.h.

88 {
89 // Copy the hash map into a map to have it ordered by key.
90 return s << GaudiUtils::Map<K, T>( m.begin(), m.end() );
91 }

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