aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/kstd/kstd/ring_buffer.hpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/libs/kstd/kstd/ring_buffer.hpp b/libs/kstd/kstd/ring_buffer.hpp
index 151ab994..6bdfce92 100644
--- a/libs/kstd/kstd/ring_buffer.hpp
+++ b/libs/kstd/kstd/ring_buffer.hpp
@@ -64,7 +64,7 @@ namespace kstd
//! @return @p true iff. this ring buffer is empty, @p false otherwise.
[[nodiscard]] constexpr auto empty() const noexcept -> bool
{
- return m_head == m_tail;
+ return m_write_index == m_read_index;
}
//! Get the size of this ring buffer.
@@ -72,12 +72,12 @@ namespace kstd
//! @return The number of elements currently stored in this ring buffer.
[[nodiscard]] constexpr auto size() const noexcept -> size_type
{
- if (m_head >= m_tail)
+ if (m_write_index >= m_read_index)
{
- return m_head - m_tail;
+ return m_write_index - m_read_index;
}
- return capacity() - m_tail + m_head;
+ return capacity() - (m_read_index - m_write_index);
}
//! Get the maximum number of elements this ring buffer can hold.
@@ -97,7 +97,7 @@ namespace kstd
constexpr auto element_at_index(size_type index) noexcept -> pointer
{
auto base_pointer = reinterpret_cast<pointer>(m_storage.data());
- auto storage_index = (m_tail + index) % capacity();
+ auto storage_index = (m_read_index + index) % capacity();
return base_pointer + storage_index;
}
@@ -116,10 +116,10 @@ namespace kstd
//! The underlying storage for the elements of this ring buffer.
alignas(ValueType) std::array<std::byte, sizeof(value_type) * Capacity> m_storage{};
- //! The index of the element that was most recently added to this ring buffer.
- size_type m_head{};
- //! The index of the element that was least recently added to this ring buffer.
- size_type m_tail{};
+ //! The index of the next element to be written.
+ size_type m_write_index{};
+ //! The index of the first element to be read.
+ size_type m_read_index{};
};
} // namespace kstd