Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active January 8, 2017 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/1a6b6063670964775c7c128a7c50ff0b to your computer and use it in GitHub Desktop.
Save deque-blog/1a6b6063670964775c7c128a7c50ff0b to your computer and use it in GitHub Desktop.
struct VariationCount
{
boost::optional<double> m_initial;
int m_count;
};
struct CountVariationBiggerThan
{
CountVariationBiggerThan(double limit) : m_limit(limit) {}
double m_limit;
VariationCount operator()() const { return VariationCount{}; }
VariationCount operator()(VariationCount gap, double val) const
{
if (!gap.m_initial)
return VariationCount { val, 0 };
if (abs(val - *gap.m_initial) > m_limit)
gap.m_count++;
return gap;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment