improved time sync

This commit is contained in:
badaix 2015-08-26 00:10:09 +02:00
parent 48ac9d2209
commit c92588344e
5 changed files with 44 additions and 17 deletions

View file

@ -37,13 +37,27 @@ public:
buffer.pop_front();
}
T median() const
T median(unsigned int mean = 1) const
{
if (buffer.empty())
return 0;
std::deque<T> tmpBuffer(buffer.begin(), buffer.end());
std::sort(tmpBuffer.begin(), tmpBuffer.end());
return tmpBuffer[tmpBuffer.size() / 2];
if ((mean <= 1) || (tmpBuffer.size() < mean))
return tmpBuffer[tmpBuffer.size() / 2];
else
{
unsigned int low = tmpBuffer.size() / 2;
unsigned int high = low;
low -= mean/2;
high += mean/2;
T result((T)0);
for (unsigned int i=low; i<=high; ++i)
{
result += tmpBuffer[i];
}
return result / mean;
}
}
double mean() const