[feat] add clear() method to Ringbuffer class

This commit is contained in:
dijunkun
2025-03-05 17:45:51 +08:00
parent cf374a0ff3
commit 0dbc0236bf

View File

@@ -58,9 +58,9 @@ class RingBuffer {
m_data = nullptr; m_data = nullptr;
} }
inline bool isEmpty() const { return m_front == m_rear; } bool isEmpty() const { return m_front == m_rear; }
inline bool isFull() const { return m_front == (m_rear + 1) % m_size; } bool isFull() const { return m_front == (m_rear + 1) % m_size; }
bool push(const T& value) { bool push(const T& value) {
if (isFull()) { if (isFull()) {
@@ -86,7 +86,7 @@ class RingBuffer {
return true; return true;
} }
inline bool pop(T& value) { bool pop(T& value) {
if (isEmpty()) { if (isEmpty()) {
return false; return false;
} }
@@ -95,11 +95,17 @@ class RingBuffer {
return true; return true;
} }
inline unsigned int front() const { return m_front; } unsigned int front() const { return m_front; }
inline unsigned int rear() const { return m_rear; } unsigned int rear() const { return m_rear; }
inline unsigned int size() const { return m_size; } unsigned int size() const { return m_size; }
bool clear() {
m_front = 0;
m_rear = 0;
return true;
}
private: private:
unsigned int m_size; unsigned int m_size;