mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
AK: Calculate CircularQueue::end() correctly (for real this time)
Both my approach and the previous approach were wrong for different cases. I've changed the Iterators index from storage-relative to queue-relative, and it's much simpler and more obviously correct. fixes #10383
This commit is contained in:
parent
c27f91142d
commit
39baadcddf
Notes:
sideshowbarker
2024-07-18 02:55:55 +09:00
Author: https://github.com/petelliott Commit: https://github.com/SerenityOS/serenity/commit/39baadcddfe Pull-request: https://github.com/SerenityOS/serenity/pull/10398 Issue: https://github.com/SerenityOS/serenity/issues/10383
@ -73,13 +73,11 @@ public:
|
|||||||
bool operator!=(const ConstIterator& other) { return m_index != other.m_index; }
|
bool operator!=(const ConstIterator& other) { return m_index != other.m_index; }
|
||||||
ConstIterator& operator++()
|
ConstIterator& operator++()
|
||||||
{
|
{
|
||||||
m_index = (m_index + 1) % Capacity;
|
++m_index;
|
||||||
if (m_index == m_queue.m_head)
|
|
||||||
m_index = m_queue.m_size;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const T& operator*() const { return m_queue.elements()[m_index]; }
|
const T& operator*() const { return m_queue.at(m_index); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CircularQueue;
|
friend class CircularQueue;
|
||||||
@ -92,8 +90,8 @@ public:
|
|||||||
size_t m_index { 0 };
|
size_t m_index { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
ConstIterator begin() const { return ConstIterator(*this, m_head); }
|
ConstIterator begin() const { return ConstIterator(*this, 0); }
|
||||||
ConstIterator end() const { return ConstIterator(*this, (m_head + size()) % Capacity); }
|
ConstIterator end() const { return ConstIterator(*this, size()); }
|
||||||
|
|
||||||
size_t head_index() const { return m_head; }
|
size_t head_index() const { return m_head; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user