17#include <unordered_map>
38 const std::string&
str,
39 StringPool::sgaux_t aux);
42 const std::string*
keyToString (StringPool::sgkey_t key,
43 StringPool::sgaux_t& aux)
const;
59 typedef std::pair<StringPool::sgaux_t, std::string>
pair_t;
74 const std::string&
str,
75 StringPool::sgaux_t aux)
77 StringPoolImpl::keymap_t::iterator i =
m_keymap.find (key);
83 else if (i->second.first != aux || i->second.second !=
str) {
100 StringPool::sgaux_t& aux)
const
102 StringPoolImpl::keymap_t::const_iterator i =
m_keymap.find (key);
104 aux = i->second.first;
105 return &i->second.second;
134 std::vector<StringPool::sgkey_t> keys;
136 for (
const keymap_t::value_type& p :
m_keymap)
137 keys.push_back (p.first);
139 for (StringPool::sgkey_t k : keys) {
140 keymap_t::const_iterator it =
m_keymap.find (k);
142 std::cout << std::hex << std::setw(18) << k <<
" "
143 << std::dec << std::setw(9) << it->second.first <<
" "
144 << it->second.second <<
"\n";
160 for (
const keymap_t::value_type& p : other.m_keymap) {
161 if (!
registerKey (p.first, p.second.second, p.second.first)) {
176StringPool::StringPool()
186StringPool::StringPool (
const StringPool& other)
196StringPool::StringPool (StringPool&& other)
201 other.m_impl = std::make_unique<StringPoolImpl>();
209StringPool& StringPool::operator= (
const StringPool& other)
211 if (
this != &other) {
222StringPool& StringPool::operator= (StringPool&& other)
224 if (
this != &other) {
226 *
m_impl = std::move (other_impl);
235StringPool::~StringPool()
250StringPool::sgkey_t StringPool::stringToKey (
const std::string& str,
256 if (
m_impl->registerKey (key, str, aux)) {
262 if (SG::isTransientKey (str)) {
264 while (!
m_impl->registerKey (new_key, str, aux)) {
265 new_key = ( (new_key+1) & sgkey_t_max);
266 if (key == new_key) std::abort();
273 const std::string* old_str =
keyToString (key, old_aux);
274 if (!old_str) std::abort();
288const std::string* StringPool::keyToString (
sgkey_t key)
const
291 return m_impl->keyToString (key, aux);
303const std::string* StringPool::keyToString (
sgkey_t key,
306 return m_impl->keyToString (key, aux);
321bool StringPool::registerKey (
sgkey_t key,
322 const std::string& str,
327 return m_impl->registerKey (key, str, aux);
334size_t StringPool::size()
const
343void StringPool::dump ()
const
352void StringPool::clear()
365bool 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.