ATLAS Offline Software
Loading...
Searching...
No Matches
IdentifierToHash< T > Class Template Reference

The IdentifierToHash table. More...

#include <IdentifierToHash.h>

Collaboration diagram for IdentifierToHash< T >:

Classes

class  RecursiveIndexCall
 Helper class for IdentifierToHash to automate recursive index call. More...
class  RecursiveIndexCall< 0, K >
class  RecursiveIndexCall< 1, K >
class  RecursiveRangeCheck
 Helper class for one-go recursive range check on all indices. More...
class  RecursiveRangeCheck< 0, K >
 N=0 is invalid. More...
class  RecursiveRangeCheck< 1, K >
 Specialise for N=1 to end recursion. More...

Public Types

enum  { NFIELDS = T::NFIELDS , NMAX =UINT_MAX }
 N is the number of fields to use from the identifier NMAX is just to make sure we get unsigned int type of enum. More...
typedef T::IdentifierType IdType
 define type IdType
typedef T::HashType HashType
 define type HashType
typedef MultiDimArray< T, NFIELDSArrayType
 define type ArrayType

Public Member Functions

 IdentifierToHash ()
 Default constructor makes empty hash table and creates default idFields object.
 IdentifierToHash (const T &idFields)
 Make empty table and initialise with idFields object.
void clear ()
 Clear the hashtable.
unsigned int size () const
 Number of valid hashes in the table.
unsigned int totalSize () const
 Total number of hashes in the table.
HashType addEntry (const IdType &id)
 Add an identifier to the table, and return the hash value belonging to it.
bool addEntry (const IdType &id, const HashType &aHash)
 Add an identifier+hash pair to the table.
HashType getHash (const IdType &id) const
 Get hash from 0 to size()-1.
void dumpOneEntry (const IdType &id, std::ostream &os) const
 Dump one entry for given id to os.
std::string dumpOneEntryToString (const IdType &id) const
 Dump one entry for given id to a string.
void dump (std::ostream &os=std::cout) const
 Dump complete table to output stream.
std::string dumpToString () const
 Dump complete table into a string.

Static Public Member Functions

static HashType defaultHashValue ()
 Helper function to get a properly initialised hash.

Private Attributes

m_idFields
unsigned int m_entries
ArrayType m_data

Detailed Description

template<class T>
class IdentifierToHash< T >

The IdentifierToHash table.

It uses a multi-dimensional array and identifier fields for fast access of Identifier-to-hash conversions. For hash-to-Identifier conversion it uses a one-dimensional array of Identifiers.

The template parameter is a helper class which is used to extract the fields from the identifier. This helper class must derive from class IdHashTableHelper, which is again a templated class, and also serves as a traits class (i.e. supplies some type definitions + number of fields).

Definition at line 39 of file IdentifierToHash.h.

Member Typedef Documentation

◆ ArrayType

template<class T>
typedef MultiDimArray<T,NFIELDS> IdentifierToHash< T >::ArrayType

define type ArrayType

Definition at line 53 of file IdentifierToHash.h.

◆ HashType

template<class T>
typedef T::HashType IdentifierToHash< T >::HashType

define type HashType

Definition at line 51 of file IdentifierToHash.h.

◆ IdType

template<class T>
typedef T::IdentifierType IdentifierToHash< T >::IdType

define type IdType

Definition at line 49 of file IdentifierToHash.h.

Member Enumeration Documentation

◆ anonymous enum

template<class T>
anonymous enum

N is the number of fields to use from the identifier NMAX is just to make sure we get unsigned int type of enum.

Enumerator
NFIELDS 
NMAX 

Definition at line 47 of file IdentifierToHash.h.

Constructor & Destructor Documentation

◆ IdentifierToHash() [1/2]

template<class T>
IdentifierToHash< T >::IdentifierToHash ( )
inline

Default constructor makes empty hash table and creates default idFields object.

Definition at line 189 of file IdentifierToHash.h.

190 : m_entries(0)
191{}
unsigned int m_entries

◆ IdentifierToHash() [2/2]

template<class T>
IdentifierToHash< T >::IdentifierToHash ( const T & idFields)
inlineexplicit

Make empty table and initialise with idFields object.

Definition at line 194 of file IdentifierToHash.h.

Member Function Documentation

◆ addEntry() [1/2]

template<class T>
HashType IdentifierToHash< T >::addEntry ( const IdType & id)

Add an identifier to the table, and return the hash value belonging to it.

Hash values start at zero, and increase by 1 at every call to addEntry(). Returns defaultHashValue() if id is invalid or was already present.

◆ addEntry() [2/2]

template<class T>
bool IdentifierToHash< T >::addEntry ( const IdType & id,
const HashType & aHash )

Add an identifier+hash pair to the table.

Returns true if the pair was added. Multiple times the same id is not allowed, but multiple times the same hash is allowed. It is therefore the responsibility of the caller to make sure that the hashes are unique (if so desired).

◆ clear()

template<class T>
void IdentifierToHash< T >::clear ( )
inline

Clear the hashtable.

Definition at line 257 of file IdentifierToHash.h.

258 {
259 m_entries = 0;
260 m_data.clear();

◆ defaultHashValue()

template<class T>
HashType IdentifierToHash< T >::defaultHashValue ( )
inlinestatic

Helper function to get a properly initialised hash.

Definition at line 55 of file IdentifierToHash.h.

55 {
56 return T::defaultHash();
57 }

◆ dump()

template<class T>
void IdentifierToHash< T >::dump ( std::ostream & os = std::cout) const
inline

Dump complete table to output stream.

Definition at line 287 of file IdentifierToHash.h.

288 {
289 m_data.dump( os );

◆ dumpOneEntry()

template<class T>
void IdentifierToHash< T >::dumpOneEntry ( const IdType & id,
std::ostream & os ) const
inline

Dump one entry for given id to os.

Definition at line 274 of file IdentifierToHash.h.

276 {
277 m_idFields.setAll( id );
278 m_data.dumpOneEntry( m_idFields, os );

◆ dumpOneEntryToString()

template<class T>
std::string IdentifierToHash< T >::dumpOneEntryToString ( const IdType & id) const
inline

Dump one entry for given id to a string.

Definition at line 281 of file IdentifierToHash.h.

282 {
283 m_idFields.setAll( id );
284 return m_data.dumpOneEntryToString( m_idFields );

◆ dumpToString()

template<class T>
std::string IdentifierToHash< T >::dumpToString ( ) const
inline

Dump complete table into a string.

Definition at line 292 of file IdentifierToHash.h.

293 {
294 return m_data.dumpToString();

◆ getHash()

template<class T>
IdentifierToHash< T >::HashType IdentifierToHash< T >::getHash ( const IdType & id) const
inline

Get hash from 0 to size()-1.

Returns invalid hash if id is not in table.

Definition at line 246 of file IdentifierToHash.h.

247 {
248 if ( !T::isValid( id ) ) return defaultHashValue();
249 m_idFields.setAll( id );
250 // check that fields are in range
252 return defaultHashValue();
253 }
static const K::ValueType & getConstRef(const K &obj, const T &indices)
static bool isInRange(const K &obj, const T &indices)
static HashType defaultHashValue()
Helper function to get a properly initialised hash.

◆ size()

template<class T>
unsigned int IdentifierToHash< T >::size ( ) const
inline

Number of valid hashes in the table.

Definition at line 263 of file IdentifierToHash.h.

264 {
265 return m_entries;

◆ totalSize()

template<class T>
unsigned int IdentifierToHash< T >::totalSize ( ) const
inline

Total number of hashes in the table.

Definition at line 269 of file IdentifierToHash.h.

270 {
271 return m_data.totalSize();

Member Data Documentation

◆ m_data

template<class T>
ArrayType IdentifierToHash< T >::m_data
private

Definition at line 185 of file IdentifierToHash.h.

◆ m_entries

template<class T>
unsigned int IdentifierToHash< T >::m_entries
private

Definition at line 184 of file IdentifierToHash.h.

◆ m_idFields

template<class T>
T IdentifierToHash< T >::m_idFields
mutableprivate

Definition at line 183 of file IdentifierToHash.h.


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