The Gaudi Framework  master (37c0b60a)
Gaudi::StringKey Class Reference

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/StringKey.h>

Collaboration diagram for Gaudi::StringKey:

Public Member Functions

 StringKey (const char *key="")
 constructor from plain C-string, perform hashing More...
 
 StringKey (std::string key)
 constructor from std::string, perform hashing More...
 
const std::stringstr () const
 the actual string More...
 
 operator const std::string & () const
 implicit cast to std::string More...
 
bool empty () const
 empty key? More...
 
bool operator! () const
 empty key? More...
 
std::size_t __hash__ () const
 the actual access to the hash More...
 
const std::string__str__ () const
 the representation of the object More...
 
std::string __repr__ () const
 the representation of the object More...
 
bool __eq__ (const StringKey &right) const
 equality operator for python More...
 
bool __eq__ (std::string_view right) const
 equality operators for python More...
 
bool __neq__ (const StringKey &right) const
 non-equality operator for python More...
 
bool __neq__ (const std::string_view right) const
 non-equality operator for python More...
 
std::string toString () const
 string representation (for properties) More...
 

Private Attributes

std::string m_str
 the actual string: More...
 
std::size_t m_hash
 the hash: More...
 

Friends

bool operator== (const StringKey &lhs, const StringKey &rhs)
 equality Key for efficiency reason compare the hash-values first More...
 
bool operator== (const StringKey &lhs, const std::string &rhs)
 equality, without hashing string rely on the native string equality More...
 
bool operator== (const std::string &lhs, const StringKey &rhs)
 
bool operator== (const StringKey &lhs, std::string_view rhs)
 
bool operator== (std::string_view lhs, const StringKey &rhs)
 
bool operator!= (const StringKey &lhs, const StringKey &rhs)
 non equality Key More...
 
bool operator!= (const StringKey &lhs, std::string_view rhs)
 non-equality string More...
 
bool operator!= (const StringKey &lhs, const std::string &rhs)
 
bool operator!= (std::string_view lhs, const StringKey &rhs)
 
bool operator!= (const std::string &lhs, const StringKey &rhs)
 
bool operator< (const StringKey &lhs, const StringKey &rhs)
 less key It can be used as a key for std::map, e.g. More...
 
bool operator> (const StringKey &lhs, const StringKey &rhs)
 greater key More...
 
bool operator<= (const StringKey &lhs, const StringKey &rhs)
 less or equal key More...
 
bool operator>= (const StringKey &lhs, const StringKey &rhs)
 greater or equal key More...
 

Detailed Description

The helper class to represent the efficient "key" for access. Essentially it is a bit modified version ("boost-free") of the original class stringKey by Gerhard Raven, which is heavily used now in HLT

Attention
NEVER use the actual hash value for anything stored in files, as it is not guaranteed that the hashing scheme will remain the same.
Author
Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@n.nosp@m.ikhe.nosp@m.f.nl
Date
2009-04-08

Definition at line 44 of file StringKey.h.

Constructor & Destructor Documentation

◆ StringKey() [1/2]

Gaudi::StringKey::StringKey ( const char *  key = "")
inline

constructor from plain C-string, perform hashing

Definition at line 48 of file StringKey.h.

48 : StringKey{ std::string{ key } } {}

◆ StringKey() [2/2]

Gaudi::StringKey::StringKey ( std::string  key)

constructor from std::string, perform hashing

Definition at line 29 of file StringKey.cpp.

30  : m_str( std::move( key ) )
31  , m_hash( std::hash<std::string>()( m_str ) ) // NB! hashing here!!!
32 {}

Member Function Documentation

◆ __eq__() [1/2]

bool Gaudi::StringKey::__eq__ ( const StringKey right) const

equality operator for python

Definition at line 47 of file StringKey.cpp.

47 { return *this == right; }

◆ __eq__() [2/2]

bool Gaudi::StringKey::__eq__ ( std::string_view  right) const

equality operators for python

Definition at line 51 of file StringKey.cpp.

51 { return *this == right; }

◆ __hash__()

std::size_t Gaudi::StringKey::__hash__ ( ) const
inline

the actual access to the hash

Attention
NEVER use the actual hash value for anything stored in files, as it is not guaranteed that the hashing scheme will remain the same. The two reason for this function are:
  • transparent usage of this object for hashmap-like containers
  • Python @reutrn the actual hash value

Definition at line 135 of file StringKey.h.

135 { return m_hash; }

◆ __neq__() [1/2]

bool Gaudi::StringKey::__neq__ ( const std::string_view  right) const

non-equality operator for python

Definition at line 59 of file StringKey.cpp.

59 { return *this != right; }

◆ __neq__() [2/2]

bool Gaudi::StringKey::__neq__ ( const StringKey right) const

non-equality operator for python

Definition at line 55 of file StringKey.cpp.

55 { return *this != right; }

◆ __repr__()

std::string Gaudi::StringKey::__repr__ ( ) const

the representation of the object

Definition at line 44 of file StringKey.cpp.

44 { return toString(); }

◆ __str__()

const std::string & Gaudi::StringKey::__str__ ( ) const

the representation of the object

Definition at line 40 of file StringKey.cpp.

40 { return m_str; }

◆ empty()

bool Gaudi::StringKey::empty ( ) const
inline

empty key?

Definition at line 60 of file StringKey.h.

60 { return m_str.empty(); }

◆ operator const std::string &()

Gaudi::StringKey::operator const std::string & ( ) const
inline

implicit cast to std::string

Definition at line 58 of file StringKey.h.

58 { return str(); }

◆ operator!()

bool Gaudi::StringKey::operator! ( ) const
inline

empty key?

Definition at line 62 of file StringKey.h.

62 { return empty(); }

◆ str()

const std::string& Gaudi::StringKey::str ( ) const
inline

the actual string

Definition at line 56 of file StringKey.h.

56 { return m_str; }

◆ toString()

std::string Gaudi::StringKey::toString ( ) const

string representation (for properties)

Definition at line 36 of file StringKey.cpp.

36 { return Gaudi::Utils::toString( m_str ); }

Friends And Related Function Documentation

◆ operator!= [1/5]

bool operator!= ( const std::string lhs,
const StringKey rhs 
)
friend

Definition at line 88 of file StringKey.h.

88 { return !( lhs == rhs ); }

◆ operator!= [2/5]

bool operator!= ( const StringKey lhs,
const std::string rhs 
)
friend

Definition at line 86 of file StringKey.h.

86 { return !( lhs == rhs ); }

◆ operator!= [3/5]

bool operator!= ( const StringKey lhs,
const StringKey rhs 
)
friend

non equality Key

Definition at line 83 of file StringKey.h.

83 { return !( lhs == rhs ); }

◆ operator!= [4/5]

bool operator!= ( const StringKey lhs,
std::string_view  rhs 
)
friend

non-equality string

Definition at line 85 of file StringKey.h.

85 { return !( lhs == rhs ); }

◆ operator!= [5/5]

bool operator!= ( std::string_view  lhs,
const StringKey rhs 
)
friend

Definition at line 87 of file StringKey.h.

87 { return !( lhs == rhs ); }

◆ operator<

bool operator< ( const StringKey lhs,
const StringKey rhs 
)
friend

less key It can be used as a key for std::map, e.g.

std::map<StringKey,double> Note that with such maps one can gain if using prehashed key:

const StringKey& key = ... ;
const MAP& m = ... ;
// EFFICIENT:
MAP::const_iterator i1 = m.find ( key ) ;
// CAN BE VERY INEFICIENT:
MAP::const_iterator i2 = m_find( "SomeLongKey,_e.g._TES_Locaiton" );

Definition at line 113 of file StringKey.h.

113  {
114  return lhs.m_hash == rhs.m_hash ? lhs.m_str < rhs.m_str : lhs.m_hash < rhs.m_hash;
115  }

◆ operator<=

bool operator<= ( const StringKey lhs,
const StringKey rhs 
)
friend

less or equal key

Definition at line 119 of file StringKey.h.

119 { return !( lhs > rhs ); }

◆ operator== [1/5]

bool operator== ( const std::string lhs,
const StringKey rhs 
)
friend

Definition at line 76 of file StringKey.h.

76 { return rhs == lhs; }

◆ operator== [2/5]

bool operator== ( const StringKey lhs,
const std::string rhs 
)
friend

equality, without hashing string rely on the native string equality

Definition at line 75 of file StringKey.h.

75 { return lhs.m_str == rhs; }

◆ operator== [3/5]

bool operator== ( const StringKey lhs,
const StringKey rhs 
)
friend

equality Key for efficiency reason compare the hash-values first

Definition at line 69 of file StringKey.h.

69  {
70  return lhs.m_hash == rhs.m_hash && lhs.m_str == rhs.m_str;
71  }

◆ operator== [4/5]

bool operator== ( const StringKey lhs,
std::string_view  rhs 
)
friend

Definition at line 77 of file StringKey.h.

77 { return lhs.m_str == rhs; }

◆ operator== [5/5]

bool operator== ( std::string_view  lhs,
const StringKey rhs 
)
friend

Definition at line 78 of file StringKey.h.

78 { return rhs == lhs; }

◆ operator>

bool operator> ( const StringKey lhs,
const StringKey rhs 
)
friend

greater key

Definition at line 117 of file StringKey.h.

117 { return rhs < lhs; }

◆ operator>=

bool operator>= ( const StringKey lhs,
const StringKey rhs 
)
friend

greater or equal key

Definition at line 121 of file StringKey.h.

121 { return !( lhs < rhs ); }

Member Data Documentation

◆ m_hash

std::size_t Gaudi::StringKey::m_hash
private

the hash:

Definition at line 160 of file StringKey.h.

◆ m_str

std::string Gaudi::StringKey::m_str
private

the actual string:

Definition at line 158 of file StringKey.h.


The documentation for this class was generated from the following files:
Gaudi::StringKey::m_str
std::string m_str
the actual string:
Definition: StringKey.h:158
std::string
STL class.
std::move
T move(T... args)
Gaudi::StringKey::m_hash
std::size_t m_hash
the hash:
Definition: StringKey.h:160
Gaudi::StringKey::StringKey
StringKey(const char *key="")
constructor from plain C-string, perform hashing
Definition: StringKey.h:48
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
std::map
STL class.
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:353
std::right
T right(T... args)
std::string::empty
T empty(T... args)
Gaudi::StringKey::str
const std::string & str() const
the actual string
Definition: StringKey.h:56
Gaudi::StringKey::toString
std::string toString() const
string representation (for properties)
Definition: StringKey.cpp:36
ProduceConsume.key
key
Definition: ProduceConsume.py:84
Gaudi::StringKey::empty
bool empty() const
empty key?
Definition: StringKey.h:60
std::hash