Reputation: 38795
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.
Upvotes: 0
Views: 179
Reputation: 54168
You could use the STL-compliant boost::circular_buffer here rather than roll your own version of that structure.
Upvotes: 0
Reputation: 28991
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.
Upvotes: 0
Reputation: 808
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.
Upvotes: 3
Reputation: 106126
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.
Upvotes: 1