The Gaudi Framework  master (37c0b60a)
GaudiUtils::Hash< T > Class Template Reference

#include <GaudiKernel/Hash.h>

Inheritance diagram for GaudiUtils::Hash< T >:

Public Member Functions

std::size_t operator() (const T &key) const
 the hash-function More...
 
std::size_t operator() (const char *key) const
 (very)specific for C-strings More...
 

Detailed Description

template<class T>
class GaudiUtils::Hash< T >

Simple hash function. The default implementation is based on boost::hash

Attention
There is no generic a'la Stroustrup implementation valid for "any" objects.
See also
GaudiUtils::GenericHash
Attention
The hashing of pointers does not rely on hash for objects

The usage requires to provide the specialization The default specialization are provided by boost::bash_value for

To provide own specialization for type TYPE or TYPE* there are four ways:

  • provide the specialization of Gaudi::Utils::Hash<TYPE>::operator() ( const TYPE& val ) const or Gaudi::Utils::Hash<TYPE*>::operator() ( const TYPE* val ) const
  • provide the full specialization of Gaudi::Utils::Hash<TYPE>
  • provide the function std::size_t hash_value ( const TYPE& val ) ;

The first and the last ways are recommended. The second way can be needed if e.g. TYPE has non trivial properties, e.g. one need to use non-const or non-ref forms of hashing value For the last way the function must reside in the same namespace, where TYPE is defines, therefore if TYPE is in a global namespace it is better to avoid this way. The most natural place for this function is a "friend function" of the class. In this way it can have access to some useful internals of the class. However this is a bit intrusive way. The third way is not recommended, since sooner or later we'll need to migrate from boost::hash to std::tr1::hash.

Comparing the previous Gaudi implementation of GaudiUtils::Hash and boost::bash specializations, one can expect:

  • some (tiny?) CPU penalty for floating point types
  • some (tiny?) CPU penalty for long-long integer types
  • better CPU performance for generic pointer types
  • guaranteed coherence of hash for std::string & C-string

Probably the first two items are compensated by better "hashing"-performance

Author
Marco Clemencic
Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@n.nosp@m.ikhe.nosp@m.f.nl
Date
2005-10-07

Definition at line 103 of file Hash.h.

Member Function Documentation

◆ operator()() [1/2]

std::size_t GaudiUtils::Hash< char * >::operator() ( const char *  key) const
inline

(very)specific for C-strings

Definition at line 163 of file Hash.h.

163  {
164  std::size_t seed = 0;
165  while ( key ) {
166  boost::hash_combine( seed, *key );
167  ++key;
168  }
169  return seed;
170  }

◆ operator()() [2/2]

template<class T >
std::size_t GaudiUtils::Hash< T >::operator() ( const T &  key) const
inline

the hash-function

the generic implementations of hash-function

Definition at line 151 of file Hash.h.

151  {
152  using namespace boost;
153  return hash_value( key );
154  }

The documentation for this class was generated from the following file:
Gaudi::hash_value
std::size_t hash_value(const Gaudi::StringKey &key)
hash-function: heeded for boost::hash
Definition: StringKey.h:174
OffloadAtlasMCRecoScenario.seed
seed
Definition: OffloadAtlasMCRecoScenario.py:52
std::size_t
ProduceConsume.key
key
Definition: ProduceConsume.py:84