|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Allocator of the nodes of a tree in an arena. More...
#include <tpl_dynSetTree.H>
Classes | |
| struct | Free_Slot |
| The room of a released node, in the list of those to give again. More... | |
Public Member Functions | |
| ArenaTreeAllocator (const size_t &sz=1024 *1024) | |
Build an arena of sz bytes. | |
| ArenaTreeAllocator (const char *base_addr, const size_t &sz) | |
Build an arena on the sz bytes at base_addr, owned by the caller. | |
| Node * | alloc_lval (const typename Node::key_type &key) override |
Build a node with a copy of key; throw bad_alloc if it does not fit. | |
| Node * | alloc_rval (typename Node::key_type &&key) override |
Build a node with key moved into it; throw bad_alloc if it does not fit. | |
| void | unalloc (Node *p) override |
Destroy the node p and keep its room, if it is of this arena. | |
| void | pin () noexcept |
| Note that some node of this arena is now in another set. | |
| bool | is_pinned () const noexcept |
Return true if some node of this arena was given to another set. | |
| void | reset () noexcept |
| Make the whole arena available again. | |
| size_t | allocated_size () const noexcept |
| Return the bytes taken from the arena, released nodes included. | |
| size_t | available_size () const noexcept |
| Return the bytes of the arena that were never taken. | |
| ~ArenaTreeAllocator ()=default | |
Public Member Functions inherited from Aleph::AbstractTreeNodeAllocator< Node > | |
| AbstractTreeNodeAllocator ()=default | |
| virtual | ~AbstractTreeNodeAllocator ()=default |
Public Attributes | |
| AhArenaAllocator | arena |
| The memory of the nodes. | |
Private Member Functions | |
| void * | take () noexcept |
| Return the room of a node, or nullptr if the arena has none left. | |
| void | give_back (void *p) noexcept |
| Release a room: the arena takes back its last block, the list any other. | |
| template<class K > | |
| Node * | build (K &&key) |
Build a node of key in a free room; throw bad_alloc if there is none. | |
Private Attributes | |
| Free_Slot * | free_slots = nullptr |
| The released rooms. | |
| bool | pinned = false |
| Whether some node was given to another set. | |
Allocator of the nodes of a tree in an arena.
The arena only takes back the last block that it gave. As every node has the same size, the allocator keeps the other released nodes in a list and gives them again before it takes more of the arena.
A set may give its nodes to another one, with join() or a split. From then on its arena is pinned: those nodes live in it, so it is never reset. And a node of another arena is destroyed, but its room is never reused.
| Node | the type of the nodes. |
Definition at line 136 of file tpl_dynSetTree.H.
|
inline |
Build an arena of sz bytes.
Definition at line 141 of file tpl_dynSetTree.H.
|
inline |
Build an arena on the sz bytes at base_addr, owned by the caller.
Definition at line 148 of file tpl_dynSetTree.H.
|
default |
|
inlineoverridevirtual |
Build a node with a copy of key; throw bad_alloc if it does not fit.
Implements Aleph::AbstractTreeNodeAllocator< Node >.
Definition at line 155 of file tpl_dynSetTree.H.
References Aleph::ArenaTreeAllocator< Node >::build().
|
inlineoverridevirtual |
Build a node with key moved into it; throw bad_alloc if it does not fit.
Implements Aleph::AbstractTreeNodeAllocator< Node >.
Definition at line 161 of file tpl_dynSetTree.H.
References Aleph::ArenaTreeAllocator< Node >::build().
|
inlinenoexcept |
Return the bytes taken from the arena, released nodes included.
Definition at line 193 of file tpl_dynSetTree.H.
References Aleph::AhArenaAllocator::allocated_size(), and Aleph::ArenaTreeAllocator< Node >::arena.
|
inlinenoexcept |
Return the bytes of the arena that were never taken.
Definition at line 199 of file tpl_dynSetTree.H.
References Aleph::ArenaTreeAllocator< Node >::arena, and Aleph::AhArenaAllocator::available_size().
|
inlineprivate |
Build a node of key in a free room; throw bad_alloc if there is none.
Definition at line 241 of file tpl_dynSetTree.H.
References ah_bad_alloc_if, Aleph::ArenaTreeAllocator< Node >::give_back(), and Aleph::ArenaTreeAllocator< Node >::take().
Referenced by Aleph::ArenaTreeAllocator< Node >::alloc_lval(), and Aleph::ArenaTreeAllocator< Node >::alloc_rval().
|
inlineprivatenoexcept |
Release a room: the arena takes back its last block, the list any other.
Definition at line 228 of file tpl_dynSetTree.H.
References Aleph::AhArenaAllocator::allocated_size(), Aleph::and, Aleph::ArenaTreeAllocator< Node >::arena, Aleph::AhArenaAllocator::dealloc(), and Aleph::ArenaTreeAllocator< Node >::free_slots.
Referenced by Aleph::ArenaTreeAllocator< Node >::build(), and Aleph::ArenaTreeAllocator< Node >::unalloc().
|
inlinenoexcept |
Return true if some node of this arena was given to another set.
Definition at line 179 of file tpl_dynSetTree.H.
|
inlinenoexcept |
Note that some node of this arena is now in another set.
Definition at line 176 of file tpl_dynSetTree.H.
References Aleph::ArenaTreeAllocator< Node >::pinned.
|
inlinenoexcept |
Make the whole arena available again.
Definition at line 185 of file tpl_dynSetTree.H.
References Aleph::ArenaTreeAllocator< Node >::arena, Aleph::ArenaTreeAllocator< Node >::free_slots, Aleph::ArenaTreeAllocator< Node >::pinned, and Aleph::AhArenaAllocator::reset().
|
inlineprivatenoexcept |
Return the room of a node, or nullptr if the arena has none left.
Definition at line 217 of file tpl_dynSetTree.H.
References Aleph::AhArenaAllocator::alloc_aligned(), Aleph::ArenaTreeAllocator< Node >::arena, Aleph::ArenaTreeAllocator< Node >::free_slots, and Aleph::ArenaTreeAllocator< Node >::Free_Slot::next.
Referenced by Aleph::ArenaTreeAllocator< Node >::build().
|
inlineoverridevirtual |
Destroy the node p and keep its room, if it is of this arena.
Implements Aleph::AbstractTreeNodeAllocator< Node >.
Definition at line 167 of file tpl_dynSetTree.H.
References Aleph::ArenaTreeAllocator< Node >::arena, Aleph::AhArenaAllocator::contains(), and Aleph::ArenaTreeAllocator< Node >::give_back().
| AhArenaAllocator Aleph::ArenaTreeAllocator< Node >::arena |
The memory of the nodes.
Definition at line 138 of file tpl_dynSetTree.H.
Referenced by Aleph::ArenaTreeAllocator< Node >::allocated_size(), Aleph::ArenaTreeAllocator< Node >::available_size(), Aleph::ArenaTreeAllocator< Node >::give_back(), Aleph::ArenaTreeAllocator< Node >::reset(), Aleph::ArenaTreeAllocator< Node >::take(), and Aleph::ArenaTreeAllocator< Node >::unalloc().
|
private |
The released rooms.
Definition at line 213 of file tpl_dynSetTree.H.
Referenced by Aleph::ArenaTreeAllocator< Node >::give_back(), Aleph::ArenaTreeAllocator< Node >::reset(), and Aleph::ArenaTreeAllocator< Node >::take().
|
private |
Whether some node was given to another set.
Definition at line 214 of file tpl_dynSetTree.H.
Referenced by Aleph::DynMapTree< Key, Type, Avl_Tree, Aleph::less< Key > >::insert(), Aleph::ArenaTreeAllocator< Node >::pin(), and Aleph::ArenaTreeAllocator< Node >::reset().