![]() |
ATLAS Offline Software
|
Maintain a mapping of strings to 64-bit ints. More...
#include <stdint.h>#include <string>#include <memory>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 |
Maintain a mapping of strings to 64-bit ints.
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.
| str | The string to look up. |
| aux | Auxiliary data to include along with the string. |
Definition in file StringPool.h.
| void clear | ( | ) |
Empty the pool.
| void dump | ( | ) | const |
Debugging dump.
Write to cout.
| const std::string * keyToString | ( | sgkey_t | key | ) | const |
Find the string corresponding to a given key.
| key | The key to look up. |
stringToKey() or registerKey(). | const std::string * keyToString | ( | sgkey_t | key, |
| sgaux_t & | aux ) const |
Find the string corresponding to a given key.
| key | The key to look up. |
| aux[out] | Auxiliary data associated with the key. |
stringToKey() or registerKey(). | bool merge | ( | const StringPool & | other | ) |
Merge another pool into this one.
| other | The 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.
| bool registerKey | ( | sgkey_t | key, |
| const std::string & | str, | ||
| sgaux_t | aux = 0 ) |
Remember an additional mapping from key to string.
| key | The key to enter. |
| str | The string to enter. |
| aux | Auxiliary data to include along with the string. |
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_t size | ( | ) | const |
Number of registered mappings.
| sgkey_t stringToKey | ( | const std::string & | str, |
| sgaux_t | aux = 0 ) |
|
private |
Definition at line 137 of file StringPool.h.