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();
186 const size_t min_capacity = 20;
187 const size_t expansion_factor = 2;
192 ::new (
p) Element_type(element);
205 const size_t min_capacity = 20;
206 const size_t expansion_factor = 2;
211 ::new (
p) Element_type(std::move(element));
237 if (
push_back(std::move(element)))
return true;
329 return erase(position, std::next(position));
355 return begin() + idx;
375 if (position !=
end()) {
393 assert(position !=
end());
394 if (position + 1 !=
end()) std::copy(position + 1,
end(), position);
420template <
typename Element_type>
436 this->
m_root = other.m_root;
438 this->
m_size = other.m_size;
440 other.init_empty_const();
441 other.m_root = this->
m_root;
444 if (
this != &other) {
475 if (this->
reserve(last - first))
return;
476 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:204
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:392
bool push_front(Element_type &&element)
Adds a new element at the front of the array.
Definition: mem_root_array.h:236
const Element_type & at(size_t n) const
Definition: mem_root_array.h:98
bool empty() const
Definition: mem_root_array.h:401
void init(MEM_ROOT *root)
Definition: mem_root_array.h:73
MEM_ROOT * m_root
Definition: mem_root_array.h:405
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:399
iterator erase(size_t ix)
Removes a single element from the array.
Definition: mem_root_array.h:339
Element_type & back()
Definition: mem_root_array.h:106
Element_type & at(size_t n)
Definition: mem_root_array.h:93
size_t size() const
Definition: mem_root_array.h:402
size_t m_capacity
Definition: mem_root_array.h:408
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:373
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:290
const Element_type * end() const
Definition: mem_root_array.h:119
size_t m_size
Definition: mem_root_array.h:407
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:223
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:352
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:400
Element_type * m_array
Definition: mem_root_array.h:406
iterator erase(const_iterator first, const_iterator last)
Erase all the elements in the specified range.
Definition: mem_root_array.h:312
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:246
void resize(size_t n, const value_type &val)
Resizes the container so that it contains n elements.
Definition: mem_root_array.h:271
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:328
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:421
Mem_root_array(MEM_ROOT *root, const_iterator first, const_iterator last)
Range constructor.
Definition: mem_root_array.h:473
Mem_root_array(Mem_root_array &&other)
Move constructor and assignment.
Definition: mem_root_array.h:435
Mem_root_array(MEM_ROOT *root, size_t n)
Definition: mem_root_array.h:451
Mem_root_array & operator=(Mem_root_array &&other)
Definition: mem_root_array.h:443
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:456
Element_type value_type
Convenience typedef, same typedef name as std::vector.
Definition: mem_root_array.h:426
Mem_root_array(const Mem_root_array &)=delete
Mem_root_array()
Definition: mem_root_array.h:430
~Mem_root_array()
Definition: mem_root_array.h:485
Mem_root_array(std::initializer_list< Element_type > elements)
Definition: mem_root_array.h:482
Mem_root_array_YY< Element_type > super
Definition: mem_root_array.h:422
Mem_root_array(MEM_ROOT *root, const Mem_root_array &x)
Definition: mem_root_array.h:479
super::const_iterator const_iterator
Definition: mem_root_array.h:428
Mem_root_array(MEM_ROOT *root)
Definition: mem_root_array.h:432
const char * p
Definition: ctype-mb.cc:1236
char * pos
Definition: do_ctype.cc:76
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:1538
const byte * find(const Pages *pages, const page_id_t &page_id) noexcept
Find a doublewrite copy of a page.
Definition: buf0dblwr.cc:2531
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:505