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.

58 lines
1.4 KiB

#pragma once
#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( minimum, maximum );
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;
}
bool operator==( const hash_t< T > &hash )
{
return hash.has_result == this->hash_result;
}
};
} // namespace llo::utils