You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
3 years ago
|
#include <cstdint>
|
||
|
#include <functional>
|
||
|
#include <random>
|
||
|
#include <type_traits>
|
||
|
#include <variant>
|
||
|
|
||
|
namespace llo::utils
|
||
|
{
|
||
|
template < class number_t > number_t generate_random_number( const number_t minimum, const number_t maximum )
|
||
|
{
|
||
|
static_assert( std::is_arithmetic_v< number_t >, "type is not arithmetic..." );
|
||
|
|
||
|
std::random_device rd;
|
||
|
std::mt19937 mt( rd() );
|
||
|
std::uniform_real_distribution< double > dist( 1.0, 10.0 );
|
||
|
return dist( mt );
|
||
|
}
|
||
|
|
||
|
template < class T > class hash_t
|
||
|
{
|
||
|
std::size_t hash_result;
|
||
|
const T data;
|
||
|
|
||
|
public:
|
||
|
hash_t()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
hash_t( const T &data ) : data{ data }
|
||
|
{
|
||
|
auto random_num =
|
||
|
llo::utils::generate_random_number< std::uint64_t >( 0, std::numeric_limits< std::uint64_t >::max() );
|
||
|
|
||
|
this->hash_result = std::hash< T >{}( data ) + std::hash< std::uint64_t >{}( random_num );
|
||
|
}
|
||
|
|
||
|
static std::shared_ptr< hash_t > make( const T &data )
|
||
|
{
|
||
|
return std::make_shared< hash_t >( data );
|
||
|
}
|
||
|
|
||
|
T &get_data() const
|
||
|
{
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
std::size_t get_hash() const
|
||
|
{
|
||
|
return hash_result;
|
||
|
}
|
||
|
};
|
||
|
} // namespace llo::utils
|