1#ifndef INPLACE_VECTOR_INCLUDED
2#define INPLACE_VECTOR_INCLUDED
59template <
typename objtype,
size_t array_size = 16>
79 size_t arr_id = index / array_size;
80 size_t slot_id = index % array_size;
81 objtype *ptr =
nullptr;
175 bool resize(
size_t new_size,
const objtype &val = objtype()) {
176 if (new_size >
size()) {
177 for (
size_t i =
size(); i < new_size; i++) {
178 if (
push_back(val) ==
nullptr)
return true;
180 }
else if (new_size <
size()) {
182 for (
size_t i = new_size; i <
size(); i++)
get_object(i)->~objtype();
185 for (
size_t j = new_size / array_size + 1; j <
m_obj_arrays.size(); j++)
271 for (
size_t i = 0; i <
size(); i++) {
Utility container class to store elements stably and scalably.
Definition: inplace_vector.h:60
const objtype & operator[](size_t i) const
STL std::vector::operator[] interface.
Definition: inplace_vector.h:247
std::vector< objtype * > m_obj_arrays
Definition: inplace_vector.h:62
bool resize(size_t new_size, const objtype &val=objtype())
STL std::vector::resize interface.
Definition: inplace_vector.h:175
void delete_all_objects()
Destroy all elements (by calling each element's destructor) stored in the vector, and then release al...
Definition: inplace_vector.h:269
const objtype & back() const
STL std::vector::back interface.
Definition: inplace_vector.h:225
objtype * get_space(size_t index)
Return an existing used slot, or append exactly one slot at end of the last array and return it.
Definition: inplace_vector.h:77
size_t m_obj_count
Definition: inplace_vector.h:64
bool empty() const
STL std::vector::empty interface.
Definition: inplace_vector.h:212
void clear()
STL std::vector::clear interface.
Definition: inplace_vector.h:219
objtype & operator[](size_t i)
STL std::vector::operator[] interface.
Definition: inplace_vector.h:259
Inplace_vector(PSI_memory_key psi_key)
Definition: inplace_vector.h:115
size_t capacity() const
STL std::vector::capacity interface.
Definition: inplace_vector.h:206
~Inplace_vector()
Release memory space and destroy all contained objects.
Definition: inplace_vector.h:124
void append_new_array()
Definition: inplace_vector.h:98
Inplace_vector(const Inplace_vector &)
Inplace_vector & operator=(const Inplace_vector &rhs)
size_t size() const
STL std::vector::size interface.
Definition: inplace_vector.h:199
objtype * push_back(const objtype &obj)
STL std::vector::push_back interface.
Definition: inplace_vector.h:157
bool m_outof_mem
Definition: inplace_vector.h:65
objtype * append_object()
Allocate space for an object, and construct it using its default constructor, and return its address.
Definition: inplace_vector.h:142
objtype * get_object(size_t index)
Get an existing element's pointer, index must be in [0, m_obj_count).
Definition: inplace_vector.h:132
objtype & back()
STL std::vector::back interface.
Definition: inplace_vector.h:235
PSI_memory_key m_psi_key
Definition: inplace_vector.h:63
const char * p
Definition: ctype-mb.cc:1225
#define MY_FAE
Definition: my_sys.h:127
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
#define MYF(v)
Definition: my_inttypes.h:97
void * my_malloc(PSI_memory_key key, size_t size, int flags)
Allocates size bytes of memory.
Definition: my_memory.cc:57
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
Common header for many mysys elements.
Performance schema instrumentation interface.