a/util: Add clear() method to HistoryBuffer

This commit is contained in:
Moses Turner 2022-06-14 12:22:12 +01:00
parent 8729c0485e
commit 9651f66c4c
2 changed files with 21 additions and 0 deletions

View file

@ -178,6 +178,9 @@ public:
const T &
back() const;
void
clear();
private:
// Make sure all valid indices can be represented in a signed integer of the same size
static_assert(MaxSize < (std::numeric_limits<size_t>::max() >> 1), "Cannot use most significant bit");
@ -187,6 +190,14 @@ private:
detail::RingBufferHelper helper_{MaxSize};
};
template <typename T, size_t MaxSize>
void
HistoryBuffer<T, MaxSize>::clear()
{
helper_.clear();
}
template <typename T, size_t MaxSize>
inline bool
HistoryBuffer<T, MaxSize>::empty() const noexcept

View file

@ -113,6 +113,9 @@ public:
size_t
back_inner_index() const noexcept;
void
clear();
private:
// Would be const, but that would mess up our ability to copy/move containers using this.
size_t capacity_;
@ -135,6 +138,13 @@ private:
};
inline void
RingBufferHelper::clear()
{
this->latest_inner_idx_ = 0;
this->length_ = 0;
}
inline size_t
RingBufferHelper::front_impl_() const noexcept
{