Bitcoin Core 28.99.0
P2P Digital Currency
|
Data structure largely mimicking std::deque, but using single preallocated ring buffer. More...
#include <vecdeque.h>
Public Member Functions | |
VecDeque () noexcept=default | |
void | resize (size_t size) |
Resize the deque to be exactly size size (adding default-constructed elements if needed). More... | |
void | clear () noexcept |
Resize the deque to be size 0. More... | |
~VecDeque () | |
Destroy a deque. More... | |
VecDeque & | operator= (const VecDeque &other) |
Copy-assign a deque. More... | |
void | swap (VecDeque &other) noexcept |
Swap two deques. More... | |
VecDeque & | operator= (VecDeque &&other) noexcept |
Move-assign a deque. More... | |
VecDeque (const VecDeque &other) | |
Copy-construct a deque. More... | |
VecDeque (VecDeque &&other) noexcept | |
Move-construct a deque. More... | |
bool friend | operator== (const VecDeque &a, const VecDeque &b) |
Equality comparison between two deques (only compares size+contents, not capacity). More... | |
std::strong_ordering friend | operator<=> (const VecDeque &a, const VecDeque &b) |
Comparison between two deques, implementing lexicographic ordering on the contents. More... | |
void | reserve (size_t capacity) |
Increase the capacity to capacity. More... | |
void | shrink_to_fit () |
Make the capacity equal to the size. More... | |
template<typename... Args> | |
void | emplace_back (Args &&... args) |
Construct a new element at the end of the deque. More... | |
void | push_back (T &&elem) |
Move-construct a new element at the end of the deque. More... | |
void | push_back (const T &elem) |
Copy-construct a new element at the end of the deque. More... | |
template<typename... Args> | |
void | emplace_front (Args &&... args) |
Construct a new element at the beginning of the deque. More... | |
void | push_front (const T &elem) |
Copy-construct a new element at the beginning of the deque. More... | |
void | push_front (T &&elem) |
Move-construct a new element at the beginning of the deque. More... | |
void | pop_front () |
Remove the first element of the deque. More... | |
void | pop_back () |
Remove the last element of the deque. More... | |
T & | front () noexcept |
Get a mutable reference to the first element of the deque. More... | |
const T & | front () const noexcept |
Get a const reference to the first element of the deque. More... | |
T & | back () noexcept |
Get a mutable reference to the last element of the deque. More... | |
const T & | back () const noexcept |
Get a const reference to the last element of the deque. More... | |
T & | operator[] (size_t idx) noexcept |
Get a mutable reference to the element in the deque at the given index. More... | |
const T & | operator[] (size_t idx) const noexcept |
Get a const reference to the element in the deque at the given index. More... | |
bool | empty () const noexcept |
Test whether the contents of this deque is empty. More... | |
size_t | size () const noexcept |
Get the number of elements in this deque. More... | |
size_t | capacity () const noexcept |
Get the capacity of this deque (maximum size it can have without reallocating). More... | |
Private Member Functions | |
size_t | FirstPart () const noexcept |
Returns the number of populated objects between m_offset and the end of the buffer. More... | |
void | Reallocate (size_t capacity) |
size_t | BufferIndex (size_t pos) const noexcept |
What index in the buffer does logical entry number pos have? More... | |
void | ResizeDown (size_t size) noexcept |
Specialization of resize() that can only shrink. More... | |
Private Attributes | |
T * | m_buffer {nullptr} |
Pointer to allocated memory. More... | |
size_t | m_offset {0} |
m_buffer + m_offset points to first object in queue. More... | |
size_t | m_size {0} |
Number of objects in the container. More... | |
size_t | m_capacity {0} |
The size of m_buffer, expressed as a multiple of the size of T. More... | |
Friends | |
void | swap (VecDeque &a, VecDeque &b) noexcept |
Non-member version of swap. More... | |
Data structure largely mimicking std::deque, but using single preallocated ring buffer.
Definition at line 24 of file vecdeque.h.
|
defaultnoexcept |
Destroy a deque.
Definition at line 129 of file vecdeque.h.
Copy-construct a deque.
Definition at line 180 of file vecdeque.h.
Move-construct a deque.
Definition at line 182 of file vecdeque.h.
Get a const reference to the last element of the deque.
Requires !empty().
Definition at line 289 of file vecdeque.h.
Get a mutable reference to the last element of the deque.
Requires !empty().
Definition at line 282 of file vecdeque.h.
What index in the buffer does logical entry number pos have?
Definition at line 75 of file vecdeque.h.
Get the capacity of this deque (maximum size it can have without reallocating).
Definition at line 314 of file vecdeque.h.
Resize the deque to be size 0.
The capacity will remain unchanged.
Definition at line 126 of file vecdeque.h.
|
inline |
Construct a new element at the end of the deque.
Definition at line 219 of file vecdeque.h.
|
inline |
Construct a new element at the beginning of the deque.
Definition at line 234 of file vecdeque.h.
Test whether the contents of this deque is empty.
Definition at line 310 of file vecdeque.h.
Returns the number of populated objects between m_offset and the end of the buffer.
Definition at line 37 of file vecdeque.h.
Get a const reference to the first element of the deque.
Requires !empty().
Definition at line 275 of file vecdeque.h.
Get a mutable reference to the first element of the deque.
Requires !empty().
Definition at line 268 of file vecdeque.h.
|
inline |
Comparison between two deques, implementing lexicographic ordering on the contents.
Definition at line 195 of file vecdeque.h.
Copy-assign a deque.
Definition at line 136 of file vecdeque.h.
Move-assign a deque.
Definition at line 173 of file vecdeque.h.
|
inline |
Equality comparison between two deques (only compares size+contents, not capacity).
Definition at line 185 of file vecdeque.h.
Get a const reference to the element in the deque at the given index.
Requires idx < size().
Definition at line 303 of file vecdeque.h.
Get a mutable reference to the element in the deque at the given index.
Requires idx < size().
Definition at line 296 of file vecdeque.h.
Remove the last element of the deque.
Requires !empty().
Definition at line 260 of file vecdeque.h.
Remove the first element of the deque.
Requires !empty().
Definition at line 250 of file vecdeque.h.
Copy-construct a new element at the end of the deque.
Definition at line 230 of file vecdeque.h.
Move-construct a new element at the end of the deque.
Definition at line 227 of file vecdeque.h.
Copy-construct a new element at the beginning of the deque.
Definition at line 244 of file vecdeque.h.
Move-construct a new element at the beginning of the deque.
Definition at line 247 of file vecdeque.h.
Definition at line 39 of file vecdeque.h.
Increase the capacity to capacity.
Capacity will not shrink.
Definition at line 206 of file vecdeque.h.
Resize the deque to be exactly size size (adding default-constructed elements if needed).
Definition at line 110 of file vecdeque.h.
Specialization of resize() that can only shrink.
Separate so that clear() can call it without requiring a default T constructor.
Definition at line 89 of file vecdeque.h.
Make the capacity equal to the size.
The contents does not change.
Definition at line 212 of file vecdeque.h.
Get the number of elements in this deque.
Definition at line 312 of file vecdeque.h.
Swap two deques.
Definition at line 161 of file vecdeque.h.
Non-member version of swap.
Definition at line 170 of file vecdeque.h.
Pointer to allocated memory.
Can contain constructed and uninitialized T objects.
Definition at line 27 of file vecdeque.h.
The size of m_buffer, expressed as a multiple of the size of T.
Definition at line 34 of file vecdeque.h.
m_buffer + m_offset points to first object in queue.
m_offset = 0 if m_capacity is 0; otherwise 0 <= m_offset < m_capacity.
Definition at line 30 of file vecdeque.h.
Number of objects in the container.
0 <= m_size <= m_capacity.
Definition at line 32 of file vecdeque.h.