29 template <
typename T >
38 throw std::runtime_error(
"history size must be > 0" );
47 const std::lock_guard< std::mutex >
lock(
_mutex );
63 T get(
float stabilization_percent = 0.75f )
const 65 if( stabilization_percent <= 0.f || stabilization_percent > 1.
f )
66 throw std::runtime_error(
"illegal stabilization percentage " 72 throw std::runtime_error(
"history is empty; no stable value" );
77 std::unordered_map< T, int > values_count_map;
78 std::pair< T, int > most_stable_value = { 0.f, 0 };
81 auto current_val = ++values_count_map[
val];
83 if( most_stable_value.second < current_val )
85 most_stable_value.first =
val;
86 most_stable_value.second = current_val;
90 auto new_value_percentage
91 = most_stable_value.second /
static_cast< float >( _values.size() );
109 const std::lock_guard< std::mutex >
lock(
_mutex );
115 const std::lock_guard< std::mutex >
lock(
_mutex );
const size_t _history_size
static const textual_icon lock
stabilized_value(size_t history_size)
stabilized_value()=delete
float _last_stable_percentage
std::string to_string(T value)