forked from premiere/premiere-libtorrent
make the sliding average class a template
This commit is contained in:
parent
50c334660d
commit
f092ddb49e
|
@ -422,10 +422,10 @@ namespace libtorrent
|
|||
cache_status m_cache_stats;
|
||||
|
||||
// keeps average queue time for disk jobs (in microseconds)
|
||||
sliding_average m_queue_time;
|
||||
sliding_average<512> m_queue_time;
|
||||
|
||||
// average read time for cache misses (in microseconds)
|
||||
sliding_average m_read_time;
|
||||
sliding_average<512> m_read_time;
|
||||
|
||||
#ifdef TORRENT_DISK_STATS
|
||||
std::ofstream m_log;
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace libtorrent
|
|||
// a sliding average accumulator. Add samples to it and it
|
||||
// keeps track of a sliding mean value and an average deviation
|
||||
// from that average.
|
||||
template <int history_size>
|
||||
struct sliding_average
|
||||
{
|
||||
sliding_average(): m_mean(-1), m_average_deviation(-1) {}
|
||||
|
@ -48,14 +49,15 @@ struct sliding_average
|
|||
}
|
||||
int deviation = abs(m_mean - s);
|
||||
|
||||
m_mean = m_mean - m_mean / 16 + s / 16;
|
||||
m_mean = m_mean - m_mean / history_size + s / history_size;
|
||||
|
||||
if (m_average_deviation == -1)
|
||||
{
|
||||
m_average_deviation = deviation;
|
||||
return;
|
||||
}
|
||||
m_average_deviation = m_average_deviation - m_average_deviation / 16 + deviation / 16;
|
||||
m_average_deviation = m_average_deviation - m_average_deviation
|
||||
/ history_size + deviation / history_size;
|
||||
}
|
||||
|
||||
int mean() const { return m_mean != -1 ? m_mean : 0; }
|
||||
|
|
Loading…
Reference in New Issue