24#ifndef MEM_ROOT_ARRAY_INCLUDED
25#define MEM_ROOT_ARRAY_INCLUDED
60template <
typename Element_type>
68 std::is_trivially_destructible<Element_type>::value;
75 assert(root !=
nullptr);
94 Element_type &
at(
size_t n) {
99 const Element_type &
at(
size_t n)
const {
140 for (
size_t ix = pos; ix <
m_size; ++ix) {
159 if (!
mem)
return true;
160 Element_type *array =
static_cast<Element_type *
>(
mem);
163 for (
size_t ix = 0; ix <
m_size; ++ix) {
164 Element_type *new_p = &array[ix];
165 Element_type *old_p = &
m_array[ix];
167 Element_type(std::move(*old_p));
169 old_p->~Element_type();
206 template <
typename... Args>
208 constexpr size_t min_capacity = 20;
209 constexpr size_t expansion_factor = 2;
216 ::new (
p) Element_type(std::forward<Args>(args)...);
242 if (
push_back(std::move(element)))
return true;
334 return erase(position, std::next(position));
358 ptrdiff_t idx = pos -
cbegin();
360 return begin() + idx;
380 if (position !=
end()) {
398 assert(position !=
end());
425template <
typename Element_type>
441 this->
m_root = other.m_root;
443 this->
m_size = other.m_size;
445 other.init_empty_const();
446 other.m_root = this->
m_root;
449 if (
this != &other) {
480 if (this->
reserve(last - first))
return;
481 for (
auto it = first; it !=
last; ++it) this->
push_back(*it);
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:61
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:196
const Element_type * const_iterator
Definition: mem_root_array.h:112
iterator erase(iterator position)
Removes a single element from the array.
Definition: mem_root_array.h:397
bool push_front(Element_type &&element)
Adds a new element at the front of the array.
Definition: mem_root_array.h:241
bool emplace_back(Args &&...args)
Constructs an element at the back of the array in-place.
Definition: mem_root_array.h:207
const Element_type & at(size_t n) const
Definition: mem_root_array.h:99
bool empty() const
Definition: mem_root_array.h:406
void init(MEM_ROOT *root)
Definition: mem_root_array.h:74
MEM_ROOT * m_root
Definition: mem_root_array.h:410
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:186
Element_type * begin()
Returns a pointer to the first element in the array.
Definition: mem_root_array.h:115
size_t capacity() const
Definition: mem_root_array.h:404
iterator erase(size_t ix)
Removes a single element from the array.
Definition: mem_root_array.h:344
Element_type & back()
Definition: mem_root_array.h:107
Element_type & at(size_t n)
Definition: mem_root_array.h:94
size_t size() const
Definition: mem_root_array.h:407
size_t m_capacity
Definition: mem_root_array.h:413
void chop(const size_t pos)
Chops the tail off the array, erasing all tail elements.
Definition: mem_root_array.h:137
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:67
size_t erase_value(const value_type &val)
Removes a single element from the array by value.
Definition: mem_root_array.h:378
Element_type * iterator
Random access iterators to value_type and const value_type.
Definition: mem_root_array.h:111
Element_type value_type
Convenience typedef, same typedef name as std::vector.
Definition: mem_root_array.h:72
const_iterator cend() const
Returns a constant pointer to the past-the-end element in the array.
Definition: mem_root_array.h:126
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:295
const Element_type * end() const
Definition: mem_root_array.h:120
size_t m_size
Definition: mem_root_array.h:412
const Element_type * begin() const
Definition: mem_root_array.h:116
bool push_front(const Element_type &element)
Adds a new element at the beginning of the array.
Definition: mem_root_array.h:228
Element_type * end()
Returns a pointer to the past-the-end element in the array.
Definition: mem_root_array.h:119
Element_type & operator[](size_t n)
Definition: mem_root_array.h:104
const Element_type & operator[](size_t n) const
Definition: mem_root_array.h:105
Element_type * data()
Definition: mem_root_array.h:91
iterator insert(const_iterator pos, const Element_type &value)
Insert an element at a given position.
Definition: mem_root_array.h:357
const_iterator cbegin() const
Returns a constant pointer to the first element in the array.
Definition: mem_root_array.h:123
size_t element_size() const
Definition: mem_root_array.h:405
Element_type * m_array
Definition: mem_root_array.h:411
iterator erase(const_iterator first, const_iterator last)
Erase all the elements in the specified range.
Definition: mem_root_array.h:317
void clear()
Erases all of the elements.
Definition: mem_root_array.h:129
const Element_type * data() const
Definition: mem_root_array.h:92
void pop_back()
Removes the last element in the array, effectively reducing the container size by one.
Definition: mem_root_array.h:251
void resize(size_t n, const value_type &val)
Resizes the container so that it contains n elements.
Definition: mem_root_array.h:276
bool reserve(size_t n)
Reserves space for array elements.
Definition: mem_root_array.h:155
void init_empty_const()
Initialize empty array that we aren't going to grow.
Definition: mem_root_array.h:84
const Element_type & back() const
Definition: mem_root_array.h:108
iterator erase(const_iterator position)
Removes a single element from the array.
Definition: mem_root_array.h:333
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Mem_root_array(MEM_ROOT *root, const_iterator first, const_iterator last)
Range constructor.
Definition: mem_root_array.h:478
Mem_root_array(Mem_root_array &&other)
Move constructor and assignment.
Definition: mem_root_array.h:440
Mem_root_array(MEM_ROOT *root, size_t n)
Definition: mem_root_array.h:456
Mem_root_array & operator=(Mem_root_array &&other)
Definition: mem_root_array.h:448
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:461
Element_type value_type
Convenience typedef, same typedef name as std::vector.
Definition: mem_root_array.h:431
Mem_root_array(const Mem_root_array &)=delete
Mem_root_array()
Definition: mem_root_array.h:435
~Mem_root_array()
Definition: mem_root_array.h:490
Mem_root_array(std::initializer_list< Element_type > elements)
Definition: mem_root_array.h:487
Mem_root_array_YY< Element_type > super
Definition: mem_root_array.h:427
Mem_root_array(MEM_ROOT *root, const Mem_root_array &x)
Definition: mem_root_array.h:484
super::const_iterator const_iterator
Definition: mem_root_array.h:433
Mem_root_array(MEM_ROOT *root)
Definition: mem_root_array.h:437
const char * p
Definition: ctype-mb.cc:1235
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:1557
void copy(Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
Copy the counters, overwrite destination.
Definition: ut0counter.h:354
Container::const_iterator find(const Container &c, Value &&value)
Definition: generic.h:39
static MEM_ROOT mem
Definition: sql_servers.cc:100
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
void * Alloc(size_t length)
Allocate memory.
Definition: my_alloc.h:145
int n
Definition: xcom_base.cc:509