27#ifndef TEMPTABLE_STORAGE_H
28#define TEMPTABLE_STORAGE_H
191 static constexpr size_t ALIGN_TO =
alignof(
void *);
350 : m_storage(const_cast<
Storage *>(storage)),
351 m_element(const_cast<
Element *>(element)) {}
358 assert(m_storage !=
nullptr || element ==
nullptr);
359 m_element =
const_cast<Element *
>(element);
368 return !(*
this == rhs);
372 assert(m_storage !=
nullptr);
373 assert(*
this != m_storage->end());
376 if (m_storage->element_last_on_page(m_element)) {
377 Page *next_page = *m_storage->element_next_page_ptr(m_element);
378 if (next_page ==
nullptr) {
380 *
this = m_storage->end();
383 m_element = m_storage->first_possible_element_on_page(next_page);
385 m_element = m_storage->next_element(m_element);
387 }
while (m_storage->element_deleted(m_element));
393 assert(m_storage !=
nullptr);
394 assert(*
this != m_storage->begin());
400 if (m_element ==
nullptr) {
401 m_element = m_storage->back();
402 }
else if (m_storage->element_first_on_page(m_element)) {
404 Page *prev_page = *m_storage->element_prev_page_ptr(m_element);
405 assert(prev_page !=
nullptr);
406 m_element = m_storage->last_possible_element_on_page(prev_page);
407 assert(m_storage->element_last_on_page(m_element));
409 m_element = m_storage->prev_element(m_element);
411 }
while (m_storage->element_deleted(m_element));
428 *
this = std::move(other);
437 rhs.m_allocator =
nullptr;
440 rhs.m_element_size = 0;
443 rhs.m_bytes_used_per_element = 0;
446 rhs.m_number_of_elements_per_page = 0;
449 rhs.m_number_of_elements = 0;
452 rhs.m_first_page =
nullptr;
455 rhs.m_last_page =
nullptr;
458 rhs.m_last_element =
nullptr;
593 m_allocator->deallocate(
static_cast<uint8_t *
>(page_to_free),
603 Iterator next_element_position = position;
604 ++next_element_position;
615 return next_element_position;
698 return reinterpret_cast<Page **
>(
static_cast<uint8_t *
>(element) -
704 return reinterpret_cast<Page **
>(
static_cast<uint8_t *
>(element) +
709 assert(element !=
nullptr);
715 assert(element !=
nullptr);
722 assert(
page !=
nullptr);
723 return static_cast<uint8_t *
>(
page) +
sizeof(
Page *);
728 assert(
page !=
nullptr);
729 return static_cast<uint8_t *
>(
page) +
sizeof(
Page *) +
734 assert(
page !=
nullptr);
735 return reinterpret_cast<Page **
>(
page);
739 assert(
page !=
nullptr);
742 return reinterpret_cast<Page **
>(
743 static_cast<uint8_t *
>(
page) +
sizeof(
Page *) +
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Custom memory allocator.
Definition: allocator.h:445
Iterator over a Storage object.
Definition: storage.h:51
bool operator!=(const Iterator &rhs) const
Compare with another iterator.
Definition: storage.h:367
Element * m_element
Current element.
Definition: storage.h:112
Iterator(const Iterator &)=default
Copy-construct from another iterator.
Iterator & operator++()
Advance the iterator one element forward.
Definition: storage.h:371
Iterator()
Default constructor.
Definition: storage.h:346
Iterator & operator=(const Iterator &)=default
Copy-assign from another iterator.
Element * operator*() const
Dereference the iterator to the element it points to.
Definition: storage.h:353
bool operator==(const Iterator &rhs) const
Compare with another iterator.
Definition: storage.h:363
Storage * m_storage
Storage over which the iterator operates.
Definition: storage.h:109
Iterator & operator--()
Recede the iterator one element backwards.
Definition: storage.h:392
Iterator & operator=(const Element *element)
Assign a new position within the same Storage object.
Definition: storage.h:357
Storage container.
Definition: storage.h:43
Element * back()
Get the last element.
Definition: storage.h:511
Allocator< uint8_t > * m_allocator
Allocator to use for allocating new pages.
Definition: storage.h:318
void Page
Type used for pages.
Definition: storage.h:48
size_t element_size() const
Get the element size.
Definition: storage.h:507
size_t page_size() const
Calculate the size of a page.
Definition: storage.h:647
Storage(const Storage &)=delete
Copy constructing is disabled, too expensive and not necessary.
Page ** element_prev_page_ptr(Element *first) const
Get the previous page.
Definition: storage.h:696
static constexpr uint8_t ELEMENT_LAST_ON_PAGE
Flag that denotes an element is the last element on a page.
Definition: storage.h:197
Element * m_last_element
Last used element in the last page of the storage.
Definition: storage.h:341
Element * last_possible_element_on_page(Page *page) const
Get the last possible element of a page (not the last occupied).
Definition: storage.h:726
Iterator end() const
Get an iterator, positioned after the last element.
Definition: storage.h:485
size_t size() const
Get the number of elements in the storage.
Definition: storage.h:509
size_t m_number_of_elements_per_page
Maximum number of elements a page can store.
Definition: storage.h:328
Page * m_last_page
Last page of the storage.
Definition: storage.h:337
bool element_last_on_page(Element *element) const
Check if element is the last on its page.
Definition: storage.h:672
Iterator begin() const
Get an iterator, positioned on the first element.
Definition: storage.h:465
size_t number_of_elements_per_page() const
A simple getter.
Definition: storage.h:643
Page ** page_next_page_ptr(Page *page) const
Get a pointer inside a page to the place denoting the next page.
Definition: storage.h:738
Element * next_element(Element *element) const
Get the next element of a given element on the same page.
Definition: storage.h:714
Page * m_first_page
First page of the storage.
Definition: storage.h:334
Element * allocate_back()
Allocate space for one more element at the end and return a pointer to it.
Definition: storage.h:513
static constexpr size_t ALIGN_TO
Align elements to this number of bytes.
Definition: storage.h:191
size_t m_bytes_used_per_element
Number of bytes used per element.
Definition: storage.h:325
void clear()
Delete all elements in the storage.
Definition: storage.h:618
static constexpr uint8_t ELEMENT_DELETED
Flag that denotes an element is deleted.
Definition: storage.h:201
Element * first_possible_element_on_page(Page *page) const
Get the first element of a page.
Definition: storage.h:720
Storage(Allocator< uint8_t > *allocator)
Constructor.
Definition: storage.h:416
static constexpr size_t META_BYTES_PER_ELEMENT
Extra bytes per element for element metadata.
Definition: storage.h:205
Page ** page_prev_page_ptr(Page *page) const
Get a pointer inside a page to the place denoting the previous page.
Definition: storage.h:733
bool element_first_on_page(Element *element) const
Check if element is the first on its page.
Definition: storage.h:659
size_t m_element_size
Element size in bytes.
Definition: storage.h:321
Storage & operator=(const Storage &)=delete
Copy assignment is disabled, too expensive and not necessary.
static constexpr size_t META_BYTES_PER_PAGE
Extra bytes per page for page metadata.
Definition: storage.h:209
~Storage()
Destructor.
Definition: storage.h:463
Iterator erase(const Iterator &position)
Delete the element pointed to by position.
Definition: storage.h:602
static constexpr uint8_t ELEMENT_FIRST_ON_PAGE
Flag that denotes an element is the first element on a page.
Definition: storage.h:194
bool element_deleted(Element *element) const
Check if element is deleted.
Definition: storage.h:684
void Element
Type used for elements.
Definition: storage.h:46
uint8_t * element_meta(Element *element) const
Get a pointer to element's meta byte(s).
Definition: storage.h:655
Page ** element_next_page_ptr(Element *last) const
Get the next page.
Definition: storage.h:702
void deallocate_back()
Destroy the last element.
Definition: storage.h:569
size_t m_number_of_elements
Number of elements in the container.
Definition: storage.h:331
Element * prev_element(Element *element) const
Get the previous element of a given element on the same page.
Definition: storage.h:708
const char * p
Definition: ctype-mb.cc:1225
int page
Definition: ctype-mb.cc:1224
Definition: allocator.h:48
constexpr size_t STORAGE_PAGE_SIZE
Storage page size.
Definition: constants.h:69
TempTable custom allocator.