23#ifndef MEM_ROOT_ARRAY_INCLUDED
24#define MEM_ROOT_ARRAY_INCLUDED
59template <
typename Element_type>
67 std::is_trivially_destructible<Element_type>::value;
74 assert(root !=
nullptr);
93 Element_type &
at(
size_t n) {
98 const Element_type &
at(
size_t n)
const {
139 for (
size_t ix = pos; ix <
m_size; ++ix) {
158 if (!
mem)
return true;
159 Element_type *array =
static_cast<Element_type *
>(
mem);
162 for (
size_t ix = 0; ix <
m_size; ++ix) {
163 Element_type *new_p = &array[ix];
164 Element_type *old_p = &
m_array[ix];
166 Element_type(std::move(*old_p));
168 old_p->~Element_type();
205 template <
typename... Args>
207 constexpr size_t min_capacity = 20;
208 constexpr size_t expansion_factor = 2;
215 ::new (
p) Element_type(std::forward<Args>(args)...);
241 if (
push_back(std::move(element)))
return true;
333 return erase(position, std::next(position));
357 ptrdiff_t idx = pos -
cbegin();
359 return begin() + idx;
379 if (position !=
end()) {
397 assert(position !=
end());
398 if (position + 1 !=
end()) std::copy(position + 1,
end(), position);
424template <
typename Element_type>
440 this->
m_root = other.m_root;
442 this->
m_size = other.m_size;
444 other.init_empty_const();
445 other.m_root = this->
m_root;
448 if (
this != &other) {
479 if (this->
reserve(last - first))
return;
480 for (
auto it = first; it !=
last; ++it) this->
push_back(*it);
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:60
bool push_back(Element_type &&element)
Adds a new element at the end of the array, after its current last element.
Definition: mem_root_array.h:195
const Element_type * const_iterator
Definition: mem_root_array.h:111
iterator erase(iterator position)
Removes a single element from the array.
Definition: mem_root_array.h:396
bool push_front(Element_type &&element)
Adds a new element at the front of the array.
Definition: mem_root_array.h:240
const Element_type & at(size_t n) const
Definition: mem_root_array.h:98
bool empty() const
Definition: mem_root_array.h:405
void init(MEM_ROOT *root)
Definition: mem_root_array.h:73
MEM_ROOT * m_root
Definition: mem_root_array.h:409
bool push_back(const Element_type &element)
Adds a new element at the end of the array, after its current last element.
Definition: mem_root_array.h:185
Element_type * begin()
Returns a pointer to the first element in the array.
Definition: mem_root_array.h:114
size_t capacity() const
Definition: mem_root_array.h:403
iterator erase(size_t ix)
Removes a single element from the array.
Definition: mem_root_array.h:343
Element_type & back()
Definition: mem_root_array.h:106
bool emplace_back(Args &&... args)
Constructs an element at the back of the array in-place.
Definition: mem_root_array.h:206
Element_type & at(size_t n)
Definition: mem_root_array.h:93
size_t size() const
Definition: mem_root_array.h:406
size_t m_capacity
Definition: mem_root_array.h:412
void chop(const size_t pos)
Chops the tail off the array, erasing all tail elements.
Definition: mem_root_array.h:136
static constexpr bool has_trivial_destructor
Is Element_type trivially destructible? If it is, we don't destroy elements when they are removed fro...
Definition: mem_root_array.h:66
size_t erase_value(const value_type &val)
Removes a single element from the array by value.
Definition: mem_root_array.h:377
Element_type * iterator
Random access iterators to value_type and const value_type.
Definition: mem_root_array.h:110
Element_type value_type
Convenience typedef, same typedef name as std::vector.
Definition: mem_root_array.h:71
const_iterator cend() const
Returns a constant pointer to the past-the-end element in the array.
Definition: mem_root_array.h:125
void resize(size_t n)
Same as resize(size_t, const value_type &val), but default-constructs the new elements.
Definition: mem_root_array.h:294
const Element_type * end() const
Definition: mem_root_array.h:119
size_t m_size
Definition: mem_root_array.h:411
const Element_type * begin() const
Definition: mem_root_array.h:115
bool push_front(const Element_type &element)
Adds a new element at the beginning of the array.
Definition: mem_root_array.h:227
Element_type * end()
Returns a pointer to the past-the-end element in the array.
Definition: mem_root_array.h:118
Element_type & operator[](size_t n)
Definition: mem_root_array.h:103
const Element_type & operator[](size_t n) const
Definition: mem_root_array.h:104
Element_type * data()
Definition: mem_root_array.h:90
iterator insert(const_iterator pos, const Element_type &value)
Insert an element at a given position.
Definition: mem_root_array.h:356
const_iterator cbegin() const
Returns a constant pointer to the first element in the array.
Definition: mem_root_array.h:122
size_t element_size() const
Definition: mem_root_array.h:404
Element_type * m_array
Definition: mem_root_array.h:410
iterator erase(const_iterator first, const_iterator last)
Erase all the elements in the specified range.
Definition: mem_root_array.h:316
void clear()
Erases all of the elements.
Definition: mem_root_array.h:128
const Element_type * data() const
Definition: mem_root_array.h:91
void pop_back()
Removes the last element in the array, effectively reducing the container size by one.
Definition: mem_root_array.h:250
void resize(size_t n, const value_type &val)
Resizes the container so that it contains n elements.
Definition: mem_root_array.h:275
bool reserve(size_t n)
Reserves space for array elements.
Definition: mem_root_array.h:154
void init_empty_const()
Initialize empty array that we aren't going to grow.
Definition: mem_root_array.h:83
const Element_type & back() const
Definition: mem_root_array.h:107
iterator erase(const_iterator position)
Removes a single element from the array.
Definition: mem_root_array.h:332
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:425
Mem_root_array(MEM_ROOT *root, const_iterator first, const_iterator last)
Range constructor.
Definition: mem_root_array.h:477
Mem_root_array(Mem_root_array &&other)
Move constructor and assignment.
Definition: mem_root_array.h:439
Mem_root_array(MEM_ROOT *root, size_t n)
Definition: mem_root_array.h:455
Mem_root_array & operator=(Mem_root_array &&other)
Definition: mem_root_array.h:447
Mem_root_array & operator=(const Mem_root_array &)=delete
Mem_root_array(MEM_ROOT *root, size_t n, const value_type &val)
Definition: mem_root_array.h:460
Element_type value_type
Convenience typedef, same typedef name as std::vector.
Definition: mem_root_array.h:430
Mem_root_array(const Mem_root_array &)=delete
Mem_root_array()
Definition: mem_root_array.h:434
~Mem_root_array()
Definition: mem_root_array.h:489
Mem_root_array(std::initializer_list< Element_type > elements)
Definition: mem_root_array.h:486
Mem_root_array_YY< Element_type > super
Definition: mem_root_array.h:426
Mem_root_array(MEM_ROOT *root, const Mem_root_array &x)
Definition: mem_root_array.h:483
super::const_iterator const_iterator
Definition: mem_root_array.h:432
Mem_root_array(MEM_ROOT *root)
Definition: mem_root_array.h:436
const char * p
Definition: ctype-mb.cc:1236
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1556
const byte * find(const Pages *pages, const page_id_t &page_id) noexcept
Find a doublewrite copy of a page.
Definition: buf0dblwr.cc:3590
static MEM_ROOT mem
Definition: sql_servers.cc:98
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
void * Alloc(size_t length)
Allocate memory.
Definition: my_alloc.h:144
int n
Definition: xcom_base.cc:508