Merge pull request #1307 from eudoxos/ringbuffer-sink

Add ringbuffer sink
This commit is contained in:
Gabi Melman
2019-11-09 21:38:57 +02:00
committed by GitHub
3 changed files with 127 additions and 0 deletions

View File

@@ -72,6 +72,27 @@ public:
return v_[head_];
}
// Return number of elements actually stored
size_t size() const
{
if (tail_ >= head_)
{
return tail_ - head_;
}
else
{
return max_items_ - (head_ - tail_ );
}
}
// Return const reference to item by index.
// If index is out of range 0…size()-1, the behavior is undefined.
const T &at(size_t i) const
{
assert(i < size());
return v_[(head_+ i) % max_items_];
}
// Pop item from front.
// If there are no elements in the container, the behavior is undefined.
void pop_front()