ATLAS Offline Software
Loading...
Searching...
No Matches
StringPool.h File Reference

Maintain a mapping of strings to 64-bit ints. More...

#include <stdint.h>
#include <string>
#include <memory>
Include dependency graph for StringPool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

sgkey_t stringToKey (const std::string &str, sgaux_t aux=0)
const std::string * keyToString (sgkey_t key) const
 Find the string corresponding to a given key.
const std::string * keyToString (sgkey_t key, sgaux_t &aux) const
 Find the string corresponding to a given key.
bool registerKey (sgkey_t key, const std::string &str, sgaux_t aux=0)
 Remember an additional mapping from key to string.
size_t size () const
 Number of registered mappings.
void dump () const
 Debugging dump.
void clear ()
 Empty the pool.
bool merge (const StringPool &other)
 Merge another pool into this one.

Variables

std::unique_ptr< StringPoolImpl > m_impl

Detailed Description

Maintain a mapping of strings to 64-bit ints.

Author
scott snyder
Date
Mar 2007

We map from strings to integer keys using a hash function. We keep a table of hashed strings so that we can later return the string given the key. We allow registering additional key->string mappings as well, as long as there aren't collisions. We also keep an auxiliary int that gets hashed along with the string.

A string can be marked as `transient' (using SG::transientKey). If we encounter a hash collision while inserting a transient key, we do not fail, but instead use find an alternate hash for it. */

namespace SG {

class StringPoolImpl;

class StringPool { public: / Type of the integer keys. typedef uint32_t sgkey_t;

/ Type of auxiliary data. typedef unsigned int sgaux_t;

/ Number of bits we'll use in the keys. / Leave a few spare bits in case we want to overload them for flags later. static const int sgkey_t_nbits = 30; static const sgkey_t sgkey_t_max = (static_cast<sgkey_t>(1) << sgkey_t_nbits) - 1;

/ Constructor. StringPool();

/ Destructor. ~StringPool();

/ Copy/move constructors. StringPool (const StringPool& other); StringPool (StringPool&& other);

/ Assignment/move operators. StringPool& operator= (const StringPool& other); StringPool& operator= (StringPool&& other);

/**

Find the key for a string.

Parameters
strThe string to look up.
auxAuxiliary data to include along with the string.
Returns
A key identifying the string. A given string will always return the same key. Will throw ExcSgkeyCollision in case of a hash collision (for a non-transient string)!

Definition in file StringPool.h.

Function Documentation

◆ clear()

void clear ( )

Empty the pool.

◆ dump()

void dump ( ) const

Debugging dump.

Write to cout.

◆ keyToString() [1/2]

const std::string * keyToString ( sgkey_t key) const

Find the string corresponding to a given key.

Parameters
keyThe key to look up.
Returns
Pointer to the string found, or null. We can find keys as long as the corresponding string was given to either stringToKey() or registerKey().

◆ keyToString() [2/2]

const std::string * keyToString ( sgkey_t key,
sgaux_t & aux ) const

Find the string corresponding to a given key.

Parameters
keyThe key to look up.
aux[out]Auxiliary data associated with the key.
Returns
Pointer to the string found, or null. We can find keys as long as the corresponding string was given to either stringToKey() or registerKey().

◆ merge()

bool merge ( const StringPool & other)

Merge another pool into this one.

Parameters
otherThe other pool to merge into this one.

In case of collisions, the colliding entries are skipped, and false is returned. If no collisions, then true is returned.

◆ registerKey()

bool registerKey ( sgkey_t key,
const std::string & str,
sgaux_t aux = 0 )

Remember an additional mapping from key to string.

Parameters
keyThe key to enter.
strThe string to enter.
auxAuxiliary data to include along with the string.
Returns
True if successful; false if the key already corresponds to a different string.

This registers an additional mapping from a key to a string; it can be found later through lookup() on the string.

◆ size()

size_t size ( ) const

Number of registered mappings.

◆ stringToKey()

sgkey_t stringToKey ( const std::string & str,
sgaux_t aux = 0 )

Variable Documentation

◆ m_impl

std::unique_ptr<StringPoolImpl> m_impl
private

Definition at line 137 of file StringPool.h.