39#include <unordered_map>
41#if defined(TIMEMORY_HASH_SOURCE) || !defined(TIMEMORY_USE_HASH_EXTERN)
53 static thread_local auto _inst =
54 get_shared_ptr_pair_instance<hash_map_t, TIMEMORY_API>();
56 auto _main = get_shared_ptr_pair_main_instance<hash_map_t, TIMEMORY_API>();
57 if(!_inst || !_main || _inst == _main)
59 auto_lock_t _lk{ type_mutex<hash_map_t>(), std::defer_lock };
62 for(
const auto& itr : *_inst)
64 if(_main->find(itr.first) == _main->end())
65 _main->emplace(itr.first, itr.second);
77 static thread_local auto _inst =
78 get_shared_ptr_pair_instance<hash_alias_map_t, TIMEMORY_API>();
80 auto _main = get_shared_ptr_pair_main_instance<hash_alias_map_t, TIMEMORY_API>();
81 if(!_inst || !_main || _inst == _main)
83 auto_lock_t _lk{ type_mutex<hash_alias_map_t>(), std::defer_lock };
86 for(
const auto& itr : *_inst)
88 if(_main->find(itr.first) == _main->end())
89 _main->emplace(itr.first, itr.second);
101 static auto _inst = []() {
102 auto _subinst = get_shared_ptr_lone_instance<hash_resolver_vec_t, TIMEMORY_API>();
103 if(_subinst && _subinst->empty())
104 _subinst->reserve(10);
153 static thread_local std::set<hash_value_t> _reported{};
162 "[%s@%s:%i]> hash identifier %llu could not be found bc the pointer to "
163 "the hash map is null\n",
172 "[%s@%s:%i]> hash identifier %llu could not be found bc the pointer to "
173 "the hash alias map is null\n",
183 for(
const auto& mitr : *_hash_map)
185 if(mitr.first == aitr.second)
188 "[%s@%s:%i]> found hash identifier %llu in alias map via "
189 "iteration after uomap->find failed! This might be an ABI or "
190 "an integer overflow problem\n",
199 for(
auto& mitr : *_hash_map)
204 "[%s@%s:%i]> found hash identifier %llu in hash map via iteration "
205 "after uomap->find failed! This might be an ABI or an integer "
206 "overflow problem\n",
208 __LINE__, (
unsigned long long)
_hash_id);
214 std::stringstream ss;
215 ss <<
"Error! node with hash " <<
_hash_id
216 <<
" does not have an associated string!\n";
217 static std::set<hash_value_t> _reported{};
221 bool _found_direct = (_hash_map->find(
_hash_id) != _hash_map->end());
222 ss <<
" Found in map : " << std::boolalpha << _found_direct <<
'\n';
224 ss <<
" Found in alias map : " << std::boolalpha << _found_alias <<
'\n';
228 ss <<
" Found aliasing : " << aitr->first <<
" -> " << aitr->second
230 auto mitr = _hash_map->find(aitr->second);
231 if(mitr != _hash_map->end())
232 ss <<
" Found mapping : " << mitr->first <<
" -> " << mitr->second
235 ss <<
" Missing mapping\n";
239 ss <<
" Missing aliasing\n";
241 ss <<
" Hash map:\n";
243 for(
const auto& itr : *_hash_map)
244 ss <<
" " << std::setw(_w) << itr.first <<
" : " << (itr.second)
248 ss <<
" Alias hash map:\n";
250 ss <<
" " << std::setw(_w) << itr.first <<
" : " << itr.second
254 if(!_registry.empty())
256 ss <<
" Static strings:\n";
257 for(
const auto* itr : _registry)
259 ss <<
" " << std::setw(_w)
260 <<
reinterpret_cast<std::size_t
>(itr) <<
" : " << itr <<
"\n";
263 fprintf(stderr,
"%s", ss.str().c_str());
284 return _hash_map->end();
313 auto itr = _hash_map->emplace(
_hash_id,
reinterpret_cast<const char*
>(
_hash_id));
314 return (
_ret = &itr.first->second,
true);
346 return (
_ret =
reinterpret_cast<const char*
>(
_hash_id),
true);
407 size_t _beg = inp.find_first_of(bdelim);
408 while(_beg != std::string::npos)
410 size_t _end = inp.find_first_of(edelim, _beg);
411 if(_end == std::string::npos)
413 auto _sz = _end - _beg - 1;
414 inp = inp.replace(_beg + 1, _sz,
demangle(inp.substr(_beg + 1, _sz)));
415 _beg = inp.find_first_of(bdelim, _end + 1);
Include the macros for hash.
const hash_alias_ptr_t hash_value_t hash_value_t _alias_hash_id
std::shared_ptr< hash_resolver_vec_t > & get_hash_resolvers()
hash_value_t add_hash_id(hash_map_ptr_t &_hash_map, string_view_cref_t _prefix)
add an string to the given hash-map (if it doesn't already exist) and return the hash
std::shared_ptr< hash_alias_map_t > hash_alias_ptr_t
hash_alias_ptr_t & get_hash_aliases()
bool get_hash_identifier(const hash_map_ptr_t &_hash_map, const hash_alias_ptr_t &_hash_alias, hash_value_t _hash_id, std::string *&_ret)
std::shared_ptr< hash_map_t > hash_map_ptr_t
const hash_alias_ptr_t hash_value_t std::string *& _ret
const hash_alias_ptr_t & _hash_alias
TIMEMORY_HASH_LINKAGE(hash_map_ptr_t &) get_hash_ids()
hash_map_t::const_iterator find_hash_identifier(const hash_map_ptr_t &_hash_map, const hash_alias_ptr_t &_hash_alias, hash_value_t _hash_id)
hash_map_ptr_t & get_hash_ids()
hash_value_t get_hash_id(Tp &&_prefix)
hash_identifier_error(_hash_map, _hash_alias, _hash_id)
std::string demangle_hash_identifier(std::string, char bdelim='[', char edelim=']')
std::unique_lock< mutex_t > auto_lock_t
Unique lock type around mutex_t.
std::string demangle(const char *_mangled_name, int *_status=nullptr)
tim::mpl::apply< std::string > string
static string_registry_t get_registry()
static bool is_registered(const char *)
provides an object which can be returned from functions that will execute the lambda provided during ...
#define TIMEMORY_TRUNCATED_FILE_STRING(FILE)