为定时样本命名循环缓冲区类?
鉴于:
class Buf {
// has fixed buffer size, forming a cyclic buffer tor t->v pairs
void add(time_type t, value_type v); // adds value v at time t, overwriting the oldest buffered value
value_type get(time_type t); // returns the value at time t1 for t1 <= t < t2 (for t1 and t2 datapoints in the buffer)
...
};
你认为这门课叫什么?
我承认这在某种程度上是主观的,但它不应该导致或需要对答案进行扩展讨论,所以我希望没关系。 :-)
到目前为止,我正在考虑 RecentValueBuffer
因为该类将(最近)时间戳映射到与这些时间戳对应的值。我对“最近”有点不确定,因为这似乎意味着时间范围/样本数量很短。
Given:
class Buf {
// has fixed buffer size, forming a cyclic buffer tor t->v pairs
void add(time_type t, value_type v); // adds value v at time t, overwriting the oldest buffered value
value_type get(time_type t); // returns the value at time t1 for t1 <= t < t2 (for t1 and t2 datapoints in the buffer)
...
};
What would you call this class?
I admit it is somehow subjective, but it shouldn't lead to or require extended discussion of the answers, so I hope it's OK. :-)
So far I'm thinking of RecentValueBuffer
since the class maps (recent) timestamps to values corresponding to these timestamps. I'm a bit unsure about "recent" because that seems to imply a short time-range/number of samples.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该问自己,类的用户是否需要知道或关心内部实现是一个循环缓冲区。如果没有,请为其命名,以明确该类的用途:可能类似于 TimeMap 之类的名称,因为它似乎将值映射到离散时间点。然后,您可以随时将内部实现更改为其他内容(例如,哈希表),而无需更改类的名称。
如果它始终是循环缓冲区对于语义很重要,那么请考虑将其设为通用容器 CircularBuffer 等,并使用模板来定义键和值的类型。
You should ask yourself if the user of the class needs to know, or care, that the internal implementation is a circular buffer. If not, name it something that makes it clear what the purpose of the class is: maybe something like
TimeMap
since it seems to be mapping values to discrete points in time. Then you can always change the internal implementation to something else (say, a Hashtable) without changing the name of your class.If it's important to the semantics that it's always a circular buffer, then consider making it a generic container
CircularBuffer
or the like and use templates to define the types of the keys and values.其目的和设计的一些有意义的方面的一些组合:
选择一个或组合任意多个,直到您对结果感到满意为止。
Some combination of a few meaningful aspects of its purpose and design:
Choose one or combine however many you like until you're happy with the result.
CircularBuffer 或 RingBuffer
我最近写了一个用于保持运行平均值(称为 RunningAverage),并将我的评论称为“环形缓冲区”,所以我显然这是我的偏好。 :) 可能是因为它更短。
CircularBuffer or RingBuffer
I wrote one recently for keeping a running average (called RunningAverage), and referred to it my comments as a 'ring buffer', so I apparently that's my preference. :) Probably because it's shorter.
您可以使用符合STL的boost::circular_buffer 在这里,而不是推出您自己的该结构版本。
You could use the STL-compliant boost::circular_buffer here rather than roll your own version of that structure.