【发布时间】:2012-08-30 07:33:55
【问题描述】:
我想创建这样的类:
public TrackMaxMin(int periodInSec)
// use current system time as time
public Add(decimal value)
// return maximum Value for the last periodInSec
public Max { get {} }
// return minimum Value for the last periodInSec
public Min { get {} }
我想我可以使用 FIFO 查询来存储 Pair<DateTime, decimal> 并且在每个 Add 调用中我应该:
- 从查询中删除“过时”的值。如果需要,删除“更新”缓存的 Max/Min 时
- 添加新值。如果需要,更新 Max/Min
我的解决方案简单明了。或许您可以提出更好的建议?
【问题讨论】:
-
你可以使用Queue class作为基础存储来构建你的类
-
“简单明了” 是好的方法的特征。