Calculate rolling / moving average in C++

前端 未结 10 2112
攒了一身酷
攒了一身酷 2020-12-02 08:09

I know this is achievable with boost as per:

Using boost::accumulators, how can I reset a rolling window size, does it keep extra history?

But I really would

10条回答
  •  醉酒成梦
    2020-12-02 08:55

    You could implement a ring buffer. Make an array of 1000 elements, and some fields to store the start and end indexes and total size. Then just store the last 1000 elements in the ring buffer, and recalculate the average as needed.

提交回复
热议问题