24#ifndef MEM_ROOT_ARRAY_INCLUDED
25#define MEM_ROOT_ARRAY_INCLUDED
61template <
typename Element_type>
69 std::is_trivially_destructible<Element_type>::value;
76 assert(root !=
nullptr);
95 Element_type &
at(
size_t n) {
100 const Element_type &
at(
size_t n)
const {
141 for (
size_t ix = pos; ix <
m_size; ++ix) {
160 if (!
mem)
return true;
161 Element_type *array =
static_cast<Element_type *
>(
mem);
164 for (
size_t ix = 0; ix <
m_size; ++ix) {
165 Element_type *new_p = &array[ix];
166 Element_type *old_p = &
m_array[ix];
168 Element_type(std::move(*old_p));
170 old_p->~Element_type();
207 template <
typename... Args>
209 constexpr size_t min_capacity = 20;
210 constexpr size_t expansion_factor = 2;
217 ::new (
p) Element_type(std::forward<Args>(args)...);
243 if (
push_back(std::move(element)))
return true;
340 return erase(position, std::next(position));
364 ptrdiff_t idx = pos -
cbegin();
366 return begin() + idx;
386 if (position !=
end()) {
404 assert(position !=
end());
431template <
typename Element_type>
447 this->
m_root = other.m_root;
449 this->
m_size = other.m_size;
451 other.init_empty_const();
452 other.m_root = this->
m_root;
455 if (
this != &other) {
486 if (this->
reserve(last - first))
return;
487 for (
auto it = first; it !=
last; ++it) this->
push_back(*it);
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:62
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:197
const Element_type * const_iterator
Definition: mem_root_array.h:113
iterator erase(iterator position)
Removes a single element from the array.
Definition: mem_root_array.h:403
bool push_front(Element_type &&element)
Adds a new element at the front of the array.
Definition: mem_root_array.h:242
bool emplace_back(Args &&...args)
Constructs an element at the back of the array in-place.
Definition: mem_root_array.h:208
const Element_type & at(size_t n) const
Definition: mem_root_array.h:100
bool empty() const
Definition: mem_root_array.h:412
void init(MEM_ROOT *root)
Definition: mem_root_array.h:75
MEM_ROOT * m_root
Definition: mem_root_array.h:416
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:187
Element_type * begin()
Returns a pointer to the first element in the array.
Definition: mem_root_array.h:116
size_t capacity() const
Definition: mem_root_array.h:410
iterator erase(size_t ix)
Removes a single element from the array.
Definition: mem_root_array.h:350
Element_type & back()
Definition: mem_root_array.h:108
Element_type & at(size_t n)
Definition: mem_root_array.h:95
size_t size() const
Definition: mem_root_array.h:413
size_t m_capacity
Definition: mem_root_array.h:419
void chop(const size_t pos)
Chops the tail off the array, erasing all tail elements.
Definition: mem_root_array.h:138
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:68
size_t erase_value(const value_type &val)
Removes a single element from the array by value.
Definition: mem_root_array.h:384
Element_type * iterator
Random access iterators to value_type and const value_type.
Definition: mem_root_array.h:112
Element_type value_type
Convenience typedef, same typedef name as std::vector.
Definition: mem_root_array.h:73
const_iterator cend() const
Returns a constant pointer to the past-the-end element in the array.
Definition: mem_root_array.h:127
const Element_type * end() const
Definition: mem_root_array.h:121
size_t m_size
Definition: mem_root_array.h:418
const Element_type * begin() const
Definition: mem_root_array.h:117
bool push_front(const Element_type &element)
Adds a new element at the beginning of the array.
Definition: mem_root_array.h:229
Element_type * end()
Returns a pointer to the past-the-end element in the array.
Definition: mem_root_array.h:120
Element_type & operator[](size_t n)
Definition: mem_root_array.h:105
const Element_type & operator[](size_t n) const
Definition: mem_root_array.h:106
Element_type * data()
Definition: mem_root_array.h:92
iterator insert(const_iterator pos, const Element_type &value)
Insert an element at a given position.
Definition: mem_root_array.h:363
const_iterator cbegin() const
Returns a constant pointer to the first element in the array.
Definition: mem_root_array.h:124
bool resize(size_t n)
Same as resize(size_t, const value_type &val), but value-initializes the new elements.
Definition: mem_root_array.h:302
bool resize(size_t n, const value_type &val)
Resizes the container so that it contains n elements.
Definition: mem_root_array.h:281
size_t element_size() const
Definition: mem_root_array.h:411
Element_type * m_array
Definition: mem_root_array.h:417
iterator erase(const_iterator first, const_iterator last)
Erase all the elements in the specified range.
Definition: mem_root_array.h:323
void clear()
Erases all of the elements.
Definition: mem_root_array.h:130
const Element_type * data() const
Definition: mem_root_array.h:93
void pop_back()
Removes the last element in the array, effectively reducing the container size by one.
Definition: mem_root_array.h:252
bool reserve(size_t n)
Reserves space for array elements.
Definition: mem_root_array.h:156
void init_empty_const()
Initialize empty array that we aren't going to grow.
Definition: mem_root_array.h:85
const Element_type & back() const
Definition: mem_root_array.h:109
iterator erase(const_iterator position)
Removes a single element from the array.
Definition: mem_root_array.h:339
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
Mem_root_array(MEM_ROOT *root, const_iterator first, const_iterator last)
Range constructor.
Definition: mem_root_array.h:484
Mem_root_array(Mem_root_array &&other)
Move constructor and assignment.
Definition: mem_root_array.h:446
Mem_root_array(MEM_ROOT *root, size_t n)
Definition: mem_root_array.h:462
Mem_root_array & operator=(Mem_root_array &&other)
Definition: mem_root_array.h:454
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:467
Element_type value_type
Convenience typedef, same typedef name as std::vector.
Definition: mem_root_array.h:437
Mem_root_array(const Mem_root_array &)=delete
Mem_root_array()
Definition: mem_root_array.h:441
~Mem_root_array()
Definition: mem_root_array.h:496
Mem_root_array(std::initializer_list< Element_type > elements)
Definition: mem_root_array.h:493
Mem_root_array_YY< Element_type > super
Definition: mem_root_array.h:433
Mem_root_array(MEM_ROOT *root, const Mem_root_array &x)
Definition: mem_root_array.h:490
super::const_iterator const_iterator
Definition: mem_root_array.h:439
Mem_root_array(MEM_ROOT *root)
Definition: mem_root_array.h:443
const char * p
Definition: ctype-mb.cc:1225
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:1577
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