1
0
forked from Alepha/Alepha

Flesh out the weight computation for Dropbox

This commit is contained in:
2024-07-25 22:11:23 -04:00
parent 2ee3aba462
commit c5d1079deb
2 changed files with 66 additions and 6 deletions

View File

@ -1 +1,2 @@
add_subdirectory( Dropbox.test )
add_subdirectory( Mailbox.test ) add_subdirectory( Mailbox.test )

View File

@ -29,6 +29,26 @@ namespace Alepha::Hydrogen::Atomic ::detail:: Dropbox_m
const bool debug= false; const bool debug= false;
const bool debugInterlock= false or C::debug; const bool debugInterlock= false or C::debug;
const bool debugPop= false or C::debug; const bool debugPop= false or C::debug;
const bool debugSSO= false or C::debug;
}
inline bool
isSSO( const std::string &s )
{
const auto base= reinterpret_cast< const char * >( &s );
if constexpr( C::debugSSO )
{
error() << "Base is: " << (void *) base << std::endl;
error() << "Data is: " << (void *) s.data() << std::endl;
error() << "Storage base is: " << sizeof( s ) << std::endl;
}
const bool result= std::less_equal{}( base, s.data() )
and std::less{}( s.data(), base + sizeof( s ) );
if( C::debugSSO and result ) error() << "Found an SSO" << std::endl;
return result;
} }
inline namespace exports inline namespace exports
@ -42,13 +62,52 @@ namespace Alepha::Hydrogen::Atomic ::detail:: Dropbox_m
using DropboxFinishedCondition= synthetic_exception< struct finished_exception, FinishedCondition, DropboxFinishedException >; using DropboxFinishedCondition= synthetic_exception< struct finished_exception, FinishedCondition, DropboxFinishedException >;
using AnyTaggedDropboxFinishedCondition= AnyTagged< DropboxFinishedCondition >; using AnyTaggedDropboxFinishedCondition= AnyTagged< DropboxFinishedCondition >;
template< typename tag > using TaggedDropboxFinishedCondition= Tagged< DropboxFinishedCondition, tag >; template< typename tag > using TaggedDropboxFinishedCondition= Tagged< DropboxFinishedCondition, tag >;
}
template< typename T >
std::size_t // TODO: Move these to somewhere more sensible...
computeWeight( const T & ) template< typename T >
{ std::size_t
return sizeof( T ); computeWeight( const T & )
{
return sizeof( T );
}
inline std::size_t
computeWeight( const std::string &s )
{
if( isSSO( s ) ) return sizeof( s );
return sizeof( s ) + s.capacity();
}
template< typename T >
std::size_t
computeWeight( const std::vector< T > &v )
{
std::size_t sz= sizeof( v ) + sizeof( T ) * ( v.capacity() - v.size() );
for( const auto &i: v )
{
sz+= computeWeight( sz );
}
return sz;
}
std::size_t
computeWeight( const Concepts::Aggregate auto &agg )
{
std::size_t rv= 0;
// This won't account for slack space... but I have to separate out
// the `sizeof` checks from the way `computeWeight` works. It's
// "good enough" for now...
template_for( agg ) <=[&]( const auto &element )
{
rv+= computeWeight( element );
};
return rv;
}
} }
/*! /*!