You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Return number of elements actually stored
size_t size() const
{
if (tail_ >= head_)
{
return tail_ - head_;
}
else
{
return max_items_ - (head_ - tail_); // is it wrong?
}
}
At where I commented, is it supposed to be "return max_items_ - 1 - (head_ - tail_);"?
An example is, when users call the following constructor to create a circular queue with max_items=3:
explicit circular_q(size_t max_items)
: max_items_(max_items + 1) // one item is reserved as marker for full q
, v_(max_items_)
{}
max_items_=4. So If the circular queue looks like this: index: 0 1 2 has element: no no yes
tail_ head_
then size() is supposed to return 1. But with current implementation, the return value is 4-(2-0)=2. I think the marker for full q should be minused here, which isn't yet.
The text was updated successfully, but these errors were encountered:
It has been changed in this commit (bad7284), but maybe missed the max_items_ = max_items + 1 in the constructor.
There is no test, so I think it is most likely a bug.
Now circular_q::size() is implemented as:
At where I commented, is it supposed to be "return max_items_ - 1 - (head_ - tail_);"?
An example is, when users call the following constructor to create a circular queue with
max_items
=3:max_items_
=4. So If the circular queue looks like this:index: 0 1 2
has element: no no yes
tail_ head_
then size() is supposed to return 1. But with current implementation, the return value is 4-(2-0)=2. I think the marker for full q should be minused here, which isn't yet.
The text was updated successfully, but these errors were encountered: