17#include <unordered_map>
37 const std::string&
str,
38 StringPool::sgaux_t aux);
41 const std::string*
keyToString (StringPool::sgkey_t key,
42 StringPool::sgaux_t& aux)
const;
58 typedef std::pair<StringPool::sgaux_t, std::string>
pair_t;
73 const std::string&
str,
74 StringPool::sgaux_t aux)
76 StringPoolImpl::keymap_t::iterator i =
m_keymap.find (key);
82 else if (i->second.first != aux || i->second.second !=
str) {
99 StringPool::sgaux_t& aux)
const
101 StringPoolImpl::keymap_t::const_iterator i =
m_keymap.find (key);
103 aux = i->second.first;
104 return &i->second.second;
133 std::vector<StringPool::sgkey_t> keys;
135 for (
const keymap_t::value_type& p :
m_keymap)
136 keys.push_back (p.first);
138 for (StringPool::sgkey_t k : keys) {
139 keymap_t::const_iterator it =
m_keymap.find (k);
141 std::println (
"{:18x} {:9} {}", k, it->second.first, it->second.second);
157 for (
const keymap_t::value_type& p : other.m_keymap) {
158 if (!
registerKey (p.first, p.second.second, p.second.first)) {
173StringPool::StringPool()
183StringPool::StringPool (
const StringPool& other)
193StringPool::StringPool (StringPool&& other)
198 other.m_impl = std::make_unique<StringPoolImpl>();
206StringPool& StringPool::operator= (
const StringPool& other)
208 if (
this != &other) {
219StringPool& StringPool::operator= (StringPool&& other)
221 if (
this != &other) {
223 *
m_impl = std::move (other_impl);
232StringPool::~StringPool()
247StringPool::sgkey_t StringPool::stringToKey (
const std::string& str,
253 if (
m_impl->registerKey (key, str, aux)) {
259 if (SG::isTransientKey (str)) {
261 while (!
m_impl->registerKey (new_key, str, aux)) {
262 new_key = ( (new_key+1) & sgkey_t_max);
263 if (key == new_key) std::abort();
270 const std::string* old_str =
keyToString (key, old_aux);
271 if (!old_str) std::abort();
285const std::string* StringPool::keyToString (
sgkey_t key)
const
288 return m_impl->keyToString (key, aux);
300const std::string* StringPool::keyToString (
sgkey_t key,
303 return m_impl->keyToString (key, aux);
318bool StringPool::registerKey (
sgkey_t key,
319 const std::string& str,
324 return m_impl->registerKey (key, str, aux);
331size_t StringPool::size()
const
340void StringPool::dump ()
const
349void StringPool::clear()
362bool StringPool::merge (
const StringPool& other)
Maintain a mapping of strings to 64-bit ints.
std::unique_ptr< StringPoolImpl > m_impl
const std::string * keyToString(sgkey_t key) const
Find the string corresponding to a given key.
sgkey_t stringToKey(const std::string &str, sgaux_t aux=0)
void clear()
Empty the pool.
Exception — sgkey hash collision.
bool merge(const StringPoolImpl &other)
Merge other pool into this one.
size_t size() const
Number of registered mappings.
std::pair< StringPool::sgaux_t, std::string > pair_t
SG::SGKeyMap< pair_t > keymap_t
void dump() const
Debugging dump. Write to stdout.
const std::string * keyToString(StringPool::sgkey_t key, StringPool::sgaux_t &aux) const
Find the string corresponding to a given key.
bool registerKey(StringPool::sgkey_t key, const std::string &str, StringPool::sgaux_t aux)
Remember an additional mapping from key to string.
A crc-64 implementation, using pclmul where possible.
uint64_t crc64(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string,.
uint64_t crc64addint(uint64_t crc, uint64_t x)
Extend a previously-calculated CRC to include an int.
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
std::unordered_map< sgkey_t, T > SGKeyMap
A map using sgkey_t as a key.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.