为定时样本命名​​循环缓冲区类?

发布于 2024-10-01 03:16:48 字数 550 浏览 3 评论 0原文

鉴于:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

两相知 2024-10-08 03:16:48

您应该问自己,类的用户是否需要知道或关心内部实现是一个循环缓冲区。如果没有,请为其命名,以明确该类的用途:可能类似于 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.

漫雪独思 2024-10-08 03:16:48

其目的和设计的一些有意义的方面的一些组合:

  • 固定大小的
  • FIFO
  • 循环
  • 缓冲区
  • 最近的
  • Last_N
  • 时间窗口

选择一个或组合任意多个,直到您对结果感到满意为止。

Some combination of a few meaningful aspects of its purpose and design:

  • Fixed_Sized
  • FIFO
  • Circular
  • Buffer
  • Recent
  • Last_N
  • Time_Window

Choose one or combine however many you like until you're happy with the result.

朦胧时间 2024-10-08 03:16:48

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.

凉风有信 2024-10-08 03:16:48

You could use the STL-compliant boost::circular_buffer here rather than roll your own version of that structure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文