17#include <unordered_map>
38 const std::string&
str,
59 typedef std::pair<StringPool::sgaux_t, std::string>
pair_t;
74 const std::string&
str,
77 StringPoolImpl::keymap_t::iterator i =
m_keymap.find (key);
83 else if (i->second.first !=
aux || i->second.second !=
str) {
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);
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)) {
201 other.m_impl = std::make_unique<StringPoolImpl>();
211 if (
this != &other) {
224 if (
this != &other) {
226 *
m_impl = std::move (other_impl);
266 if (key == new_key) std::abort();
273 const std::string* old_str =
keyToString (key, old_aux);
274 if (!old_str) std::abort();
322 const std::string&
str,
367 return m_impl->merge (*other.m_impl);
Maintain a mapping of strings to 64-bit ints.
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.
unsigned int sgaux_t
Type of auxiliary data.
bool registerKey(sgkey_t key, const std::string &str, sgaux_t aux=0)
Remember an additional mapping from key to string.
std::unique_ptr< StringPoolImpl > m_impl
void dump() const
Debugging dump.
const std::string * keyToString(sgkey_t key) const
Find the string corresponding to a given key.
static const sgkey_t sgkey_t_max
size_t size() const
Number of registered mappings.
bool merge(const StringPool &other)
Merge another pool into this one.
sgkey_t stringToKey(const std::string &str, sgaux_t aux=0)
Find the key for a string.
uint32_t sgkey_t
Type of the integer keys.
StringPool & operator=(const StringPool &other)
Assignment/move operators.
void clear()
Empty the pool.
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.
std::unordered_map< sgkey_t, T > SGKeyMap
A map using sgkey_t as a key.
bool isTransientKey(const std::string &key)
Test to see if a key is transoent.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.