17#if ALIB_MONOMEM && ALIB_CONTAINERS
21# include <unordered_map>
22# include <unordered_set>
27namespace alib {
namespace boxing {
namespace detail {
31#if ALIB_MONOMEM && ALIB_CONTAINERS
36 extern std::unordered_set<TypeFunctors::Key, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownCustomFunctions;
37 extern std::unordered_map<TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTables;
38 extern std::unordered_map<TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTablesArray;
41extern ALIB_API void DbgLockMaps(
bool doLock );
49 struct CustomFunctionKey
51 const FunctionTable* Parent;
52 const std::type_info&
Type;
54 CustomFunctionKey(
const FunctionTable* parent,
const std::type_info& type )
60 struct CustomFunctionMapped
63ALIB_DBG(uinteger DbgCntInvocations; )
65 CustomFunctionMapped(
void* implementation )
66 : Implementation (implementation)
72 struct CustomFunctionHash
74 std::size_t operator()(
const CustomFunctionKey& key)
const
76 size_t result=
reinterpret_cast<size_t>(key.Parent)
77 ^ key.Type.hash_code();
78 result^= (result << 21 );
79 result^= (result >> 11);
85 struct CustomFunctionEqualTo
87 bool operator()(
const CustomFunctionKey& lhs,
const CustomFunctionKey& rhs)
const
89 return lhs.Parent == rhs.Parent
90 && lhs.Type == rhs.Type;
94 #if ALIB_MONOMEM && ALIB_CONTAINERS
96 CustomFunctionKey, CustomFunctionMapped,
100 std::unordered_map< CustomFunctionKey, CustomFunctionMapped,
102 CustomFunctionEqualTo > customFunctionMap;
114#if (ALIB_MONOMEM && ALIB_CONTAINERS && ALIB_DEBUG)
117 #if ALIB_MONOMEM && ALIB_DEBUG_BOXING
118 DbgKnownCustomFunctions.Reset();
119 DbgKnownVTables .Reset();
120 DbgKnownVTablesArray .Reset();
122 customFunctionMap .Reset();
129#if ALIB_MONOMEM && ALIB_CONTAINERS
130 auto it= customFunctionMap.Find( CustomFunctionKey(
this, rtti) );
132 auto it= customFunctionMap.find( CustomFunctionKey(
this, rtti) );
134 if ( it != customFunctionMap.end() )
137 ++it->second.DbgCntInvocations; )
138 return it->second.Implementation;
145 #if ALIB_DEBUG_BOXING
146 detail::DbgLockMaps(
true);
148 DbgKnownCustomFunctions.InsertIfNotExistent( &rtti );
150 DbgKnownCustomFunctions.emplace( &rtti );
152 detail::DbgLockMaps(
false);
156 #if ALIB_MONOMEM && ALIB_CONTAINERS
157 customFunctionMap.InsertOrAssign( CustomFunctionKey(
this, rtti), CustomFunctionMapped(impl) );
159 if( customFunctionMap.size() == 0 )
160 customFunctionMap.reserve( 50 );
161 customFunctionMap.insert_or_assign( CustomFunctionKey(
this, rtti), CustomFunctionMapped(impl) );
168using namespace detail;
179 std::vector<detail::VTable*> result;
181 result.reserve(
size_t(
182 DbgKnownVTables .Size()
183 + DbgKnownVTablesArray.Size() ) );
185 result.reserve( DbgKnownVTables .size()
186 + DbgKnownVTablesArray.size() );
189 for(
int type= 0 ; type < 2 ; ++type )
191 auto& map= type == 0 ? DbgKnownVTables
192 : DbgKnownVTablesArray;
193 for(
auto it= map.begin() ; it!= map.end() ; ++it )
194 result.emplace_back( it->second );
203 std::vector<std::pair<const std::type_info*,uinteger>> result;
214 detail::DbgLockMaps(
true);
216 for (
auto* typeIt : detail::DbgKnownCustomFunctions )
219 auto usage= (std::numeric_limits<uinteger>::max)();
226 if( implIt != customFunctionMap.end() )
227 usage= implIt->second.DbgCntInvocations;
229 result.emplace_back( typeIt, usage );
232 detail::DbgLockMaps(
false);
238 std::vector<std::pair<const std::type_info*,uinteger>>& output )
253 for(
auto funcIt= customFunctionMap.begin() ; funcIt != customFunctionMap.end() ; ++funcIt )
254 if( funcIt->first.Parent == &functionTable )
255 output.emplace_back( &funcIt->first.Type , funcIt->second.DbgCntInvocations );
260#if ALIB_DEBUG_CONTAINERS
286DOX_MARKER([DOX_BOXING_OPTIMIZE_DEFINE_1])
288DOX_MARKER([DOX_BOXING_OPTIMIZE_DEFINE_1])
291#if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
306 #if ALIB_SIZEOF_INTEGER == 8
314#if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
317#if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
321#if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
330DOX_MARKER([DOX_BOXING_OPTIMIZE_DEFINE_2])
332DOX_MARKER([DOX_BOXING_OPTIMIZE_DEFINE_2])
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
#define IF_ALIB_STRINGS(...)
#define ALIB_BOXING_VTABLE_DEFINE_ARRAYTYPE(TMapped, Identifier)
#define IF_ALIB_MONOMEM(...)
FunctionTable DEFAULT_FUNCTIONS
The default box-functions set.
AString DbgDumpDistribution(const THashtable &hashtable, bool detailedBucketList)
const alib::boxing::Box & Type
Inclusion
Denotes how members of a set something should be taken into account.
ValueReference
Denotes if a value is interpreted as an absolute or relative number.
Whitespaces
Denotes whether a string is trimmed or not.
CreateDefaults
Denotes whether default entities should be created or not.
Caching
Denotes if a cache mechanism is enabled or disabled.
Side
Denotes if something is left or right.
Propagation
Denotes whether a e.g a setting should be propagated.
Switch
Denotes if sth. is switched on or off.
Initialization
Used for example with constructors that allow to suppress initialization of members.
Safeness
Denotes whether something should be performed in a safe or unsafe fashion.
SortOrder
Denotes sort order.
Reach
Denotes the reach of something.
SourceData
Denotes if the source data should be moved or copied.
Timezone
Denotes whether a time value represents local time or UTC.
Case
Denotes upper and lower case character treatment.
Alignment
Denotes Alignments.
Timing
Denotes if asynchronous tasks become synchronized.
CreateIfNotExists
Denotes whether something should be created if it does not exist.
Phase
Denotes a phase, e.g.,of a transaction.
ContainerOp
Denotes standard container operations.
ALIB_API MonoAllocator GLOBAL_ALLOCATOR
containers::HashSet< TAllocator, T, THash, TEqual, THashCaching, TRecycling > HashSet
Type alias in namespace alib. See type definition alib::containers::HashSet.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
containers::HashMap< TAllocator, TKey, TMapped, THash, TEqual, THashCaching, TRecycling > HashMap
Type alias in namespace alib.
static ALIB_API std::vector< std::pair< const std::type_info *, uinteger > > GetKnownFunctionTypes()
static ALIB_API void DumpCustomFunctionHashMapMetrics(AString &target, bool detailedBucketList)
static ALIB_API void getFunctionTypes(const detail::FunctionTable &input, std::vector< std::pair< const std::type_info *, uinteger > > &output)
static ALIB_API std::vector< detail::VTable * > GetKnownVTables()
uinteger DbgCntInvocationsFHashcode
Debug-compilation counter for the number of invocations.
uinteger DbgCntInvocationsFIsNotNull
Debug-compilation counter for the number of invocations.
FAppend< character, lang::HeapAllocator >::Signature fAppend
Entry for built-in function FAppend<character>.
FIsLess::Signature fIsLess
Entry for built-in function FIsLess.
ALIB_API void * getCustom(const std::type_info &rtti, bool isInvocation) const
uinteger DbgCntInvocationsFIsLess
Debug-compilation counter for the number of invocations.
uinteger DbgCntInvocationsFClone
Debug-compilation counter for the number of invocations.
uinteger DbgCntInvocationsFAppend
Debug-compilation counter for the number of invocations.
uinteger DbgCntInvocationsFIsTrue
Debug-compilation counter for the number of invocations.
ALIB_API void setCustom(const std::type_info &rtti, void *implementation)
uinteger DbgCntInvocationsFEquals
Debug-compilation counter for the number of invocations.
FClone::Signature fClone
Entry for built-in function FClone.
FHashcode::Signature fHashcode
Entry for built-in function FHashcode.
FIsTrue::Signature fIsTrue
Entry for built-in function FIsTrue.
static ALIB_API void Shutdown()
Needs to be called only in debug versions to shut down internal hashtables cleanly.
FEquals::Signature fEquals
Entry for built-in function FEquals.
FIsNotNull::Signature fIsNotNull
Entry for built-in function FIsNotNull.