mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
AK: Add CircularDeque.
This class inherits from CircularQueue and adds the ability dequeue from the end of the queue using dequeue_end(). Note that I had to make some of CircularQueue's fields protected to properly implement dequeue_end.
This commit is contained in:
parent
f11c85f4a7
commit
67041f3a8c
Notes:
sideshowbarker
2024-07-19 11:37:15 +09:00
Author: https://github.com/DrewStratford Commit: https://github.com/SerenityOS/serenity/commit/67041f3a8c6 Pull-request: https://github.com/SerenityOS/serenity/pull/675 Reviewed-by: https://github.com/awesomekling
24
AK/CircularDeque.h
Normal file
24
AK/CircularDeque.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/CircularQueue.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<typename T, int Capacity>
|
||||
class CircularDeque : public CircularQueue<T, Capacity> {
|
||||
|
||||
public:
|
||||
T dequeue_end()
|
||||
{
|
||||
ASSERT(!this->is_empty());
|
||||
T value = this->m_elements[(this->m_head + this->m_size - 1) % Capacity];
|
||||
this->m_size--;
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using AK::CircularDeque;
|
@ -77,7 +77,7 @@ public:
|
||||
|
||||
int head_index() const { return m_head; }
|
||||
|
||||
private:
|
||||
protected:
|
||||
friend class ConstIterator;
|
||||
T m_elements[Capacity];
|
||||
int m_size { 0 };
|
||||
|
Loading…
Reference in New Issue
Block a user