![]() |
MySQL 8.0.43
Source Code Documentation
|
Storage container. More...
#include <storage.h>
Classes | |
| class | Iterator |
| Iterator over a Storage object. More... | |
Public Types | |
| typedef void | Element |
| Type used for elements. More... | |
| typedef void | Page |
| Type used for pages. More... | |
Public Member Functions | |
| Storage (Allocator< uint8_t > *allocator) | |
| Constructor. More... | |
| Storage (const Storage &)=delete | |
| Copy constructing is disabled, too expensive and not necessary. More... | |
| Storage & | operator= (const Storage &)=delete |
| Copy assignment is disabled, too expensive and not necessary. More... | |
| Storage (Storage &&other) | |
| Move constructor. More... | |
| Storage & | operator= (Storage &&rhs) |
| Move assignment. More... | |
| ~Storage () | |
| Destructor. More... | |
| Iterator | begin () const |
| Get an iterator, positioned on the first element. More... | |
| Iterator | end () const |
| Get an iterator, positioned after the last element. More... | |
| void | element_size (size_t element_size) |
| Set the element size. More... | |
| size_t | element_size () const |
| Get the element size. More... | |
| size_t | size () const |
| Get the number of elements in the storage. More... | |
| Element * | back () |
| Get the last element. More... | |
| Element * | allocate_back () |
| Allocate space for one more element at the end and return a pointer to it. More... | |
| void | deallocate_back () |
| Destroy the last element. More... | |
| Iterator | erase (const Iterator &position) |
Delete the element pointed to by position. More... | |
| void | clear () |
| Delete all elements in the storage. More... | |
| size_t | number_of_elements_per_page () const |
| A simple getter. More... | |
Private Member Functions | |
| size_t | page_size () const |
| Calculate the size of a page. More... | |
| uint8_t * | element_meta (Element *element) const |
| Get a pointer to element's meta byte(s). More... | |
| bool | element_first_on_page (Element *element) const |
| Check if element is the first on its page. More... | |
| void | element_first_on_page (bool first_on_page, Element *element) |
| Set element's first-on-page flag. More... | |
| bool | element_last_on_page (Element *element) const |
| Check if element is the last on its page. More... | |
| void | element_last_on_page (bool last_on_page, Element *element) |
| Set element's last-on-page flag. More... | |
| bool | element_deleted (Element *element) const |
| Check if element is deleted. More... | |
| void | element_deleted (bool deleted, Element *element) |
| Set element's deleted flag. More... | |
| Page ** | element_prev_page_ptr (Element *first) const |
| Get the previous page. More... | |
| Page ** | element_next_page_ptr (Element *last) const |
| Get the next page. More... | |
| Element * | prev_element (Element *element) const |
| Get the previous element of a given element on the same page. More... | |
| Element * | next_element (Element *element) const |
| Get the next element of a given element on the same page. More... | |
| Element * | first_possible_element_on_page (Page *page) const |
| Get the first element of a page. More... | |
| Element * | last_possible_element_on_page (Page *page) const |
| Get the last possible element of a page (not the last occupied). More... | |
| Page ** | page_prev_page_ptr (Page *page) const |
| Get a pointer inside a page to the place denoting the previous page. More... | |
| Page ** | page_next_page_ptr (Page *page) const |
| Get a pointer inside a page to the place denoting the next page. More... | |
Private Attributes | |
| Allocator< uint8_t > * | m_allocator |
| Allocator to use for allocating new pages. More... | |
| size_t | m_element_size |
| Element size in bytes. More... | |
| size_t | m_bytes_used_per_element |
| Number of bytes used per element. More... | |
| size_t | m_number_of_elements_per_page |
| Maximum number of elements a page can store. More... | |
| size_t | m_number_of_elements |
| Number of elements in the container. More... | |
| Page * | m_first_page |
| First page of the storage. More... | |
| Page * | m_last_page |
| Last page of the storage. More... | |
| Element * | m_last_element |
| Last used element in the last page of the storage. More... | |
Static Private Attributes | |
| static constexpr size_t | ALIGN_TO = alignof(void *) |
| Align elements to this number of bytes. More... | |
| static constexpr uint8_t | ELEMENT_FIRST_ON_PAGE = 0x1 |
| Flag that denotes an element is the first element on a page. More... | |
| static constexpr uint8_t | ELEMENT_LAST_ON_PAGE = 0x2 |
| Flag that denotes an element is the last element on a page. More... | |
| static constexpr uint8_t | ELEMENT_DELETED = 0x4 |
| Flag that denotes an element is deleted. More... | |
| static constexpr size_t | META_BYTES_PER_ELEMENT = 1 |
| Extra bytes per element for element metadata. More... | |
| static constexpr size_t | META_BYTES_PER_PAGE = 2 * sizeof(Page *) |
| Extra bytes per page for page metadata. More... | |
Storage container.
This mimics std::vector and std::deque with the difference that the size of the objects that are being stored in it can be determined at runtime. Elements are stored next to each other in a pre-allocated pages of fixed size STORAGE_PAGE_SIZE.
| typedef void temptable::Storage::Element |
Type used for elements.
We treat elements as black boxes.
| typedef void temptable::Storage::Page |
Type used for pages.
|
inlineexplicit |
Constructor.
| [in,out] | allocator | Allocator to use for allocating pages. |
|
delete |
Copy constructing is disabled, too expensive and not necessary.
|
inline |
Move constructor.
| [in,out] | other | Object whose state to grasp, after this call the state of `other` is undefined. |
|
inline |
Destructor.
|
inline |
Allocate space for one more element at the end and return a pointer to it.
This will increase size() by one.
|
inline |
Get the last element.
|
inline |
Get an iterator, positioned on the first element.
|
inline |
Delete all elements in the storage.
After this size() will be zero.
|
inline |
Destroy the last element.
This will decrease size() by one.
|
inlineprivate |
Set element's deleted flag.
| [in] | deleted | Flag to set, true if deleted. |
| [in,out] | element | Element to modify. |
|
inlineprivate |
Check if element is deleted.
| [in] | element | Element to check. |
|
inlineprivate |
Set element's first-on-page flag.
| [in] | first_on_page | Flag to set, true if first on page. |
| [in,out] | element | Element to modify. |
|
inlineprivate |
Check if element is the first on its page.
If the element is the first, then the previous page pointer is stored right before that element (and its meta bytes).
| [in] | element | Element to check. |
|
inlineprivate |
Set element's last-on-page flag.
| [in] | last_on_page | Flag to set, true if last on page. |
| [in,out] | element | Element to modify. |
|
inlineprivate |
Check if element is the last on its page.
If the element is the last, then the next page pointer is stored right after that element.
| [in] | element | Element to check. |
|
inlineprivate |
Get a pointer to element's meta byte(s).
| [in] | element | Element whose meta byte(s) to get a pointer to. |
|
inlineprivate |
Get the next page.
Undefined if !element_last_on_page().
| [in] | last | The last element on a page. |
|
inlineprivate |
Get the previous page.
Undefined if !element_first_on_page().
| [in] | first | The first element on a page. |
|
inline |
Get the element size.
|
inline |
Set the element size.
Only allowed if the storage is empty.
| [in] | element_size | New element size to set, in bytes. |
|
inline |
Get an iterator, positioned after the last element.
|
inline |
Delete the element pointed to by position.
Subsequent or previous iterators are not invalidated. The memory occupied by the deleted element is not returned to the underlying allocator.
position points to the last element before this call) | [in] | position | Delete element at this position. |
|
inlineprivate |
Get the first element of a page.
| [in] | page | Page whose first element to fetch. |
|
inlineprivate |
Get the last possible element of a page (not the last occupied).
| [in] | page | Page whose last element to fetch. |
|
inlineprivate |
Get the next element of a given element on the same page.
Undefined if this is the last element on the page.
| [in] | element | Element whose sibling in the page to fetch. |
|
inline |
A simple getter.
Copy assignment is disabled, too expensive and not necessary.
Move assignment.
| [in,out] | rhs | Object whose state to grasp, after this call the state of `rhs` is undefined. |
|
inlineprivate |
Get a pointer inside a page to the place denoting the next page.
| [in] | page | Page whose next to fetch. |
|
inlineprivate |
Get a pointer inside a page to the place denoting the previous page.
| [in] | page | Page whose previous to fetch. |
|
inlineprivate |
Calculate the size of a page.
This is usually a little bit less than STORAGE_PAGE_SIZE. For example if STORAGE_PAGE_SIZE == 100 and our element size is 10 and we need 4 extra bytes per page, then the calculated page size will be 94: 9 elements (10 bytes each) and the extra 4 bytes.
|
inlineprivate |
Get the previous element of a given element on the same page.
Undefined if this is the first element on the page.
| [in] | element | Element whose sibling in the page to fetch. |
|
inline |
Get the number of elements in the storage.
|
staticconstexprprivate |
Align elements to this number of bytes.
|
staticconstexprprivate |
Flag that denotes an element is deleted.
Deleted elements are skipped during iteration.
|
staticconstexprprivate |
Flag that denotes an element is the first element on a page.
|
staticconstexprprivate |
Flag that denotes an element is the last element on a page.
|
private |
Allocator to use for allocating new pages.
|
private |
Number of bytes used per element.
This accounts for element size, alignment and our element meta bytes.
|
private |
Element size in bytes.
|
private |
First page of the storage.
|
private |
Last used element in the last page of the storage.
The last page may not be fully occupied, so this may point somewhere in the middle of it.
|
private |
Last page of the storage.
|
private |
Number of elements in the container.
Not counting deleted ones.
|
private |
Maximum number of elements a page can store.
|
staticconstexprprivate |
Extra bytes per element for element metadata.
It must store all ELEMENT_* bits.
|
staticconstexprprivate |
Extra bytes per page for page metadata.
This stores the previous and next page pointers.