Skip to content

Commit

Permalink
more direct RingQueue is_full() calculation; edited RingQueue constru…
Browse files Browse the repository at this point in the history
…ctor documentation to clarify condition for the "full" state
  • Loading branch information
mihir-mihir committed Jun 26, 2024
1 parent 92291f7 commit 7d91eb3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/internal_modules/roc_core/ring_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ template <class T, size_t EmbeddedCapacity = 0> class RingQueue : public NonCopy
public:
//! Initialize.
//! @remarks
//! Preallocate buffer in @p arena with @p max_len number of elements.
//! Preallocate buffer in @p arena with @p max_len number of elements. In this
//! implementation, an empty slot needs to be reserved in the buffer to be able to
//! distinguish between empty and full states, so queue's working capacity is
//! `max_len - 1` (the queue is full when the buffer is filled with `max_len - 1`
//! elements).
RingQueue(core::IArena& arena, size_t max_len)
: buff_(NULL)
, buff_len_(max_len)
Expand All @@ -63,7 +67,7 @@ template <class T, size_t EmbeddedCapacity = 0> class RingQueue : public NonCopy
return buff_ != NULL;
}

//! Get maximum number of elements in queue/
//! Get maximum number of elements in queue.
size_t capacity() const {
return buff_len_ - 1;
}
Expand All @@ -80,7 +84,7 @@ template <class T, size_t EmbeddedCapacity = 0> class RingQueue : public NonCopy

//! Is the queue full.
bool is_full() {
return size() == capacity();
return begin_ == (end_ + 1) % buff_len_;
}

//! Get reference of the front element.
Expand Down

0 comments on commit 7d91eb3

Please sign in to comment.