|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Stack of the frames of a depth-first search that does not recurse. More...
#include <tpl_dfs_stack.H>
Public Member Functions | |
| Dfs_Stack () noexcept=default | |
| Builds an empty stack, which takes the room that the thread kept when it first needs room. | |
| Dfs_Stack (Dfs_Stack &&other) noexcept | |
| Takes the frames and the room of other, which is left empty. | |
| Dfs_Stack & | operator= (Dfs_Stack &&other) noexcept |
| Takes the frames and the room of other, which is left with the room of this stack and no frames. | |
| ~Dfs_Stack () | |
| Destroys the frames; the thread keeps the room, if it fits in 1 MiB and is larger than the one kept. | |
| template<class... Args> | |
| T & | push (Args &&...args) |
| Builds a frame on top of the stack. | |
| void | pop () noexcept |
| Destroys the top frame; the stack must not be empty. | |
| T & | top () noexcept |
| The top frame; the stack must not be empty. | |
| bool | is_empty () const noexcept |
| Whether the stack has no frames. | |
| size_t | size () const noexcept |
| The number of frames. | |
| size_t | capacity () const noexcept |
| The number of frames that fit in the room of the stack, 0 while it has none. | |
| void | clear () noexcept |
| Destroys all the frames, and keeps the room. | |
| void | release () noexcept |
| Destroys all the frames, and gives the room back. | |
Private Member Functions | |
| void | set_room (void *r, size_t bytes) noexcept |
| void | give_room_back () noexcept |
| void | grow () |
| void | enlarge () |
| template<class... Args> | |
| T & | push_in_poisoned_room (Args &&...args) |
Private Attributes | |
| void * | room = nullptr |
| size_t | room_bytes = 0 |
| T * | base = nullptr |
| T * | top_ptr = nullptr |
| T * | limit = nullptr |
Static Private Attributes | |
| static constexpr size_t | Initial_Capacity = sizeof(T) < 1000 ? 1000 / sizeof(T) : 1 |
| static constexpr size_t | Second_Capacity = 256 |
Stack of the frames of a depth-first search that does not recurse.
The frames are contiguous and built in place, so that the top one is reached through a pointer, as a frame of the call stack is, and a frame is moved only when the stack grows. A reference to a frame stays valid until the stack grows.
When the stack is destroyed or released, its room, up to 1 MiB, is kept for the next stack of the thread, so that a search that follows allocates nothing; the room that it took from the thread goes back to the thread when the stack outgrows it, so that a search that goes beyond 1 MiB does not leave the thread without room. A stack that never needs room costs nothing. An allocation of 1 KiB or more also makes glibc merge its small free blocks, which then slows down those of the graph algorithms: the first room is smaller, so that a search that does not go deep does not cause it; the second has 256 frames.
Under AddressSanitizer, with ALEPH_ANNOTATE_CONTAINERS defined for the whole program, as MemArray asks, the part of the room that holds no frame cannot be reached: the use of a frame that was popped, or of the room of a stack that is gone, is reported.
| T | Type of the frames. |
Definition at line 240 of file tpl_dfs_stack.H.
|
defaultnoexcept |
Builds an empty stack, which takes the room that the thread kept when it first needs room.
|
inlinenoexcept |
Takes the frames and the room of other, which is left empty.
Definition at line 388 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::set_room().
|
inline |
Destroys the frames; the thread keeps the room, if it fits in 1 MiB and is larger than the one kept.
Definition at line 410 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::clear(), Aleph::Dfs_Stack< T >::give_room_back(), and Aleph::Dfs_Stack< T >::room.
|
inlinenoexcept |
The number of frames that fit in the room of the stack, 0 while it has none.
Definition at line 473 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::base, and Aleph::Dfs_Stack< T >::limit.
Referenced by TEST(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inlinenoexcept |
Destroys all the frames, and keeps the room.
Definition at line 479 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::base, Aleph::dfs_stack_detail::poison(), Aleph::dfs_stack_detail::Poisoned, Aleph::Dfs_Stack< T >::size(), and Aleph::Dfs_Stack< T >::top_ptr.
Referenced by Aleph::Dfs_Stack< T >::~Dfs_Stack(), Aleph::Find_Path_Depth_First< GT, Itor, SA >::find_path(), Aleph::Dfs_Stack< T >::operator=(), Aleph::Dfs_Stack< T >::release(), TEST(), TEST(), and TEST_F().
|
inlineprivate |
Definition at line 321 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::base, Aleph::dfs_stack_detail::free_room(), Aleph::Dfs_Stack< T >::give_room_back(), Aleph::Dfs_Stack< T >::Initial_Capacity, Aleph::dfs_stack_detail::kept_room(), Aleph::dfs_stack_detail::poison(), Aleph::Dfs_Stack< T >::room, Aleph::Dfs_Stack< T >::room_bytes, Aleph::Dfs_Stack< T >::Second_Capacity, Aleph::Dfs_Stack< T >::set_room(), Aleph::Dfs_Stack< T >::size(), and Aleph::Dfs_Stack< T >::top_ptr.
Referenced by Aleph::Dfs_Stack< T >::grow().
|
inlineprivatenoexcept |
Definition at line 273 of file tpl_dfs_stack.H.
References Aleph::and, Aleph::dfs_stack_detail::Room::base, Aleph::dfs_stack_detail::Room::bytes, Aleph::dfs_stack_detail::free_room(), Aleph::dfs_stack_detail::kept_room(), Aleph::dfs_stack_detail::Room::open, Aleph::dfs_stack_detail::poison(), Aleph::Dfs_Stack< T >::room, and Aleph::Dfs_Stack< T >::room_bytes.
Referenced by Aleph::Dfs_Stack< T >::~Dfs_Stack(), Aleph::Dfs_Stack< T >::enlarge(), and Aleph::Dfs_Stack< T >::release().
|
inlineprivate |
Definition at line 292 of file tpl_dfs_stack.H.
References Aleph::dfs_stack_detail::Room::base, Aleph::dfs_stack_detail::Room::bytes, Aleph::Dfs_Stack< T >::enlarge(), Aleph::dfs_stack_detail::open_room(), Aleph::Dfs_Stack< T >::room, and Aleph::Dfs_Stack< T >::set_room().
Referenced by Aleph::Dfs_Stack< T >::push().
|
inlinenoexcept |
Whether the stack has no frames.
Definition at line 460 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::base, and Aleph::Dfs_Stack< T >::top_ptr.
Referenced by Aleph::__depth_first_traversal(), Aleph::Compute_Bridges< GT, SA >::__dfs(), Aleph::Depth_First_Traversal< GT, Operation, SA >::__dft(), Aleph::__find_depth_first_spanning_tree(), Aleph::__find_path_depth_first(), Aleph::__is_graph_acyclique(), Aleph::__map_subgraph(), Aleph::__test_cycle(), Aleph::__test_for_path(), Aleph::bin_to_tree(), Aleph::graph_to_tree_detail::build(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::build_combinatorial_embedding_linear_lr(), Aleph::build_subgraph(), Aleph::Build_Subgraph< GT, SA >::build_subgraph(), Aleph::Build_Subgraph< GT, SA >::build_subgraph(), Aleph::Find_Depth_First_Spanning_Tree< GT, SA >::build_tree(), Aleph::Compute_Cut_Nodes< GT, SA >::cut_nodes(), Aleph::Find_Path_Depth_First< GT, Itor, SA >::find_path(), Aleph::forest_to_bin(), Aleph::generate_tree_graphviz(), Aleph::Bellman_Ford< GT, Distance, Ait, NAit, SA >::get_distance(), Aleph::Is_Graph_Acyclique< GT, SA >::is_acyclique(), Aleph::Compute_Cut_Nodes< GT, SA >::map_subgraph(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::orient_dfs(), Aleph::Compute_Cut_Nodes< GT, SA >::paint_subgraph(), Aleph::kosaraju_detail::search(), Aleph::Tarjan_Connected_Components< GT, Itor, SA >::search(), TEST(), TEST(), Aleph::Test_For_Cycle< GT, SA >::test_cycle(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::test_dfs(), TEST_F(), TEST_F(), Aleph::Test_For_Path< GT, SA >::test_path(), Aleph::Topological_Sort< GT, Itor, SA >::topological_sort(), and Aleph::df_tree_detail::Df_Low_Builder< GT, Node_Label, SA >::visit().
|
inlinenoexcept |
Takes the frames and the room of other, which is left with the room of this stack and no frames.
Definition at line 397 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::base, Aleph::Dfs_Stack< T >::clear(), Aleph::Dfs_Stack< T >::limit, Aleph::Dfs_Stack< T >::room, Aleph::Dfs_Stack< T >::room_bytes, and Aleph::Dfs_Stack< T >::top_ptr.
|
inlinenoexcept |
Destroys the top frame; the stack must not be empty.
Definition at line 445 of file tpl_dfs_stack.H.
References Aleph::dfs_stack_detail::poison(), Aleph::dfs_stack_detail::Poisoned, and Aleph::Dfs_Stack< T >::top_ptr.
Referenced by Aleph::__depth_first_traversal(), Aleph::Compute_Bridges< GT, SA >::__dfs(), Aleph::Depth_First_Traversal< GT, Operation, SA >::__dft(), Aleph::__find_depth_first_spanning_tree(), Aleph::__find_path_depth_first(), Aleph::__is_graph_acyclique(), Aleph::__map_subgraph(), Aleph::__test_cycle(), Aleph::__test_for_path(), Aleph::__tree_postorder_traversal(), Aleph::__tree_preorder_traversal(), Aleph::bin_to_tree(), Aleph::graph_to_tree_detail::build(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::build_combinatorial_embedding_linear_lr(), Aleph::build_subgraph(), Aleph::Build_Subgraph< GT, SA >::build_subgraph(), Aleph::Build_Subgraph< GT, SA >::build_subgraph(), Aleph::Find_Depth_First_Spanning_Tree< GT, SA >::build_tree(), Aleph::Compute_Cut_Nodes< GT, SA >::cut_nodes(), Aleph::Find_Path_Depth_First< GT, Itor, SA >::find_path(), Aleph::forest_to_bin(), Aleph::generate_tree_graphviz(), Aleph::Bellman_Ford< GT, Distance, Ait, NAit, SA >::get_distance(), Aleph::Is_Graph_Acyclique< GT, SA >::is_acyclique(), Aleph::Compute_Cut_Nodes< GT, SA >::map_subgraph(), Aleph::df_tree_detail::number_tree(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::orient_dfs(), Aleph::Compute_Cut_Nodes< GT, SA >::paint_subgraph(), Aleph::kosaraju_detail::search(), Aleph::Tarjan_Connected_Components< GT, Itor, SA >::search(), TEST(), TEST(), TEST(), Aleph::Test_For_Cycle< GT, SA >::test_cycle(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::test_dfs(), TEST_F(), Aleph::Test_For_Path< GT, SA >::test_path(), Aleph::Topological_Sort< GT, Itor, SA >::topological_sort(), and Aleph::df_tree_detail::Df_Low_Builder< GT, Node_Label, SA >::visit().
|
inline |
Builds a frame on top of the stack.
| args | Arguments for the constructor of the frame. |
| bad_alloc | if there is not enough memory; anything that the constructor of the frame throws, or, when the stack grows, the copy or the move of a frame. Then the stack is as it was, but for the frames that cannot be copied that the stack moved before one threw. |
Definition at line 430 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::grow(), Aleph::Dfs_Stack< T >::limit, Aleph::dfs_stack_detail::Poisoned, Aleph::Dfs_Stack< T >::push_in_poisoned_room(), and Aleph::Dfs_Stack< T >::top_ptr.
Referenced by Aleph::__depth_first_traversal(), Aleph::Compute_Bridges< GT, SA >::__dfs(), Aleph::Depth_First_Traversal< GT, Operation, SA >::__dft(), Aleph::__find_depth_first_spanning_tree(), Aleph::__find_path_depth_first(), Aleph::__is_graph_acyclique(), Aleph::__map_subgraph(), Aleph::__test_cycle(), Aleph::__test_for_path(), Aleph::__tree_postorder_traversal(), Aleph::__tree_preorder_traversal(), Aleph::bin_to_tree(), Aleph::graph_to_tree_detail::build(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::build_combinatorial_embedding_linear_lr(), Aleph::build_subgraph(), Aleph::Build_Subgraph< GT, SA >::build_subgraph(), Aleph::Build_Subgraph< GT, SA >::build_subgraph(), Aleph::Find_Depth_First_Spanning_Tree< GT, SA >::build_tree(), Aleph::Find_Path_Depth_First< GT, Itor, SA >::find_path(), Aleph::forest_to_bin(), Aleph::generate_tree_graphviz(), Aleph::Bellman_Ford< GT, Distance, Ait, NAit, SA >::get_distance(), Aleph::Is_Graph_Acyclique< GT, SA >::is_acyclique(), Aleph::Compute_Cut_Nodes< GT, SA >::map_subgraph(), Aleph::df_tree_detail::number_tree(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::orient_dfs(), Aleph::Compute_Cut_Nodes< GT, SA >::paint_subgraph(), Aleph::kosaraju_detail::search(), Aleph::Tarjan_Connected_Components< GT, Itor, SA >::search(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), Aleph::Test_For_Cycle< GT, SA >::test_cycle(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::test_dfs(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), Aleph::Test_For_Path< GT, SA >::test_path(), Aleph::Topological_Sort< GT, Itor, SA >::topological_sort(), Aleph::Compute_Cut_Nodes< GT, SA >::visit(), and Aleph::df_tree_detail::Df_Low_Builder< GT, Node_Label, SA >::visit().
|
inlineprivate |
Definition at line 361 of file tpl_dfs_stack.H.
References Aleph::dfs_stack_detail::poison(), Aleph::Dfs_Stack< T >::top_ptr, and Aleph::dfs_stack_detail::unpoison().
Referenced by Aleph::Dfs_Stack< T >::push().
|
inlinenoexcept |
Destroys all the frames, and gives the room back.
The thread keeps the room, as when the stack is destroyed, if it fits in 1 MiB and is larger than the one kept; else it is freed. The stack is left without room, which it takes again, from the thread if it can, when a frame is pushed.
Definition at line 494 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::clear(), Aleph::Dfs_Stack< T >::give_room_back(), Aleph::Dfs_Stack< T >::room, and Aleph::Dfs_Stack< T >::set_room().
|
inlineprivatenoexcept |
Definition at line 259 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::base, Aleph::Dfs_Stack< T >::limit, r, Aleph::Dfs_Stack< T >::room, Aleph::Dfs_Stack< T >::room_bytes, and Aleph::Dfs_Stack< T >::top_ptr.
Referenced by Aleph::Dfs_Stack< T >::Dfs_Stack(), Aleph::Dfs_Stack< T >::enlarge(), Aleph::Dfs_Stack< T >::grow(), and Aleph::Dfs_Stack< T >::release().
|
inlinenoexcept |
The number of frames.
Definition at line 466 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::base, and Aleph::Dfs_Stack< T >::top_ptr.
Referenced by Aleph::Dfs_Stack< T >::clear(), Aleph::Dfs_Stack< T >::enlarge(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), and TEST_F().
|
inlinenoexcept |
The top frame; the stack must not be empty.
Definition at line 454 of file tpl_dfs_stack.H.
References Aleph::Dfs_Stack< T >::top_ptr.
Referenced by Aleph::__depth_first_traversal(), Aleph::Compute_Bridges< GT, SA >::__dfs(), Aleph::Depth_First_Traversal< GT, Operation, SA >::__dft(), Aleph::__find_depth_first_spanning_tree(), Aleph::__find_path_depth_first(), Aleph::__is_graph_acyclique(), Aleph::__map_subgraph(), Aleph::__test_cycle(), Aleph::__test_for_path(), Aleph::__tree_postorder_traversal(), Aleph::__tree_preorder_traversal(), Aleph::bin_to_tree(), Aleph::graph_to_tree_detail::build(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::build_combinatorial_embedding_linear_lr(), Aleph::build_subgraph(), Aleph::Build_Subgraph< GT, SA >::build_subgraph(), Aleph::Build_Subgraph< GT, SA >::build_subgraph(), Aleph::Find_Depth_First_Spanning_Tree< GT, SA >::build_tree(), Aleph::Compute_Cut_Nodes< GT, SA >::cut_nodes(), Aleph::Find_Path_Depth_First< GT, Itor, SA >::find_path(), Aleph::forest_to_bin(), Aleph::generate_tree_graphviz(), Aleph::Bellman_Ford< GT, Distance, Ait, NAit, SA >::get_distance(), Aleph::Is_Graph_Acyclique< GT, SA >::is_acyclique(), Aleph::Compute_Cut_Nodes< GT, SA >::map_subgraph(), Aleph::df_tree_detail::number_tree(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::orient_dfs(), Aleph::Compute_Cut_Nodes< GT, SA >::paint_subgraph(), Aleph::kosaraju_detail::search(), Aleph::Tarjan_Connected_Components< GT, Itor, SA >::search(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), Aleph::Test_For_Cycle< GT, SA >::test_cycle(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::test_dfs(), TEST_F(), TEST_F(), TEST_F(), Aleph::Test_For_Path< GT, SA >::test_path(), Aleph::Topological_Sort< GT, Itor, SA >::topological_sort(), and Aleph::df_tree_detail::Df_Low_Builder< GT, Node_Label, SA >::visit().
|
private |
Definition at line 255 of file tpl_dfs_stack.H.
Referenced by Aleph::Dfs_Stack< T >::capacity(), Aleph::Dfs_Stack< T >::clear(), Aleph::Dfs_Stack< T >::enlarge(), Aleph::Dfs_Stack< T >::is_empty(), Aleph::Dfs_Stack< T >::operator=(), Aleph::Dfs_Stack< T >::set_room(), and Aleph::Dfs_Stack< T >::size().
|
staticconstexprprivate |
Definition at line 247 of file tpl_dfs_stack.H.
Referenced by Aleph::Dfs_Stack< T >::enlarge().
|
private |
Definition at line 257 of file tpl_dfs_stack.H.
Referenced by Aleph::Dfs_Stack< T >::capacity(), Aleph::Dfs_Stack< T >::operator=(), Aleph::Dfs_Stack< T >::push(), and Aleph::Dfs_Stack< T >::set_room().
|
private |
Definition at line 253 of file tpl_dfs_stack.H.
Referenced by Aleph::Dfs_Stack< T >::~Dfs_Stack(), Aleph::Dfs_Stack< T >::enlarge(), Aleph::Dfs_Stack< T >::give_room_back(), Aleph::Dfs_Stack< T >::grow(), Aleph::Dfs_Stack< T >::operator=(), Aleph::Dfs_Stack< T >::release(), and Aleph::Dfs_Stack< T >::set_room().
|
private |
Definition at line 254 of file tpl_dfs_stack.H.
Referenced by Aleph::Dfs_Stack< T >::enlarge(), Aleph::Dfs_Stack< T >::give_room_back(), Aleph::Dfs_Stack< T >::operator=(), and Aleph::Dfs_Stack< T >::set_room().
|
staticconstexprprivate |
Definition at line 251 of file tpl_dfs_stack.H.
Referenced by Aleph::Dfs_Stack< T >::enlarge().
|
private |
Definition at line 256 of file tpl_dfs_stack.H.
Referenced by Aleph::Dfs_Stack< T >::clear(), Aleph::Dfs_Stack< T >::enlarge(), Aleph::Dfs_Stack< T >::is_empty(), Aleph::Dfs_Stack< T >::operator=(), Aleph::Dfs_Stack< T >::pop(), Aleph::Dfs_Stack< T >::push(), Aleph::Dfs_Stack< T >::push_in_poisoned_room(), Aleph::Dfs_Stack< T >::set_room(), Aleph::Dfs_Stack< T >::size(), and Aleph::Dfs_Stack< T >::top().