Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Dfs_Stack< T > Class Template Reference

Stack of the frames of a depth-first search that does not recurse. More...

#include <tpl_dfs_stack.H>

Collaboration diagram for Aleph::Dfs_Stack< T >:
[legend]

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
 

Detailed Description

template<class T>
class Aleph::Dfs_Stack< T >

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.

Template Parameters
TType of the frames.

Definition at line 240 of file tpl_dfs_stack.H.

Constructor & Destructor Documentation

◆ Dfs_Stack() [1/2]

template<class T >
Aleph::Dfs_Stack< T >::Dfs_Stack ( )
defaultnoexcept

Builds an empty stack, which takes the room that the thread kept when it first needs room.

◆ Dfs_Stack() [2/2]

template<class T >
Aleph::Dfs_Stack< T >::Dfs_Stack ( Dfs_Stack< T > &&  other)
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().

◆ ~Dfs_Stack()

template<class T >
Aleph::Dfs_Stack< T >::~Dfs_Stack ( )
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.

Member Function Documentation

◆ capacity()

template<class T >
size_t Aleph::Dfs_Stack< T >::capacity ( ) const
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().

◆ clear()

◆ enlarge()

◆ give_room_back()

◆ grow()

◆ is_empty()

template<class T >
bool Aleph::Dfs_Stack< T >::is_empty ( ) const
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().

◆ operator=()

template<class T >
Dfs_Stack & Aleph::Dfs_Stack< T >::operator= ( Dfs_Stack< T > &&  other)
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.

◆ pop()

template<class T >
void Aleph::Dfs_Stack< T >::pop ( )
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().

◆ push()

template<class T >
template<class... Args>
T & Aleph::Dfs_Stack< T >::push ( Args &&...  args)
inline

Builds a frame on top of the stack.

Parameters
argsArguments for the constructor of the frame.
Returns
Reference to the new frame.
Exceptions
bad_allocif 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.
Note
Always inlined, since a search pushes a frame for each node.

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().

◆ push_in_poisoned_room()

template<class T >
template<class... Args>
T & Aleph::Dfs_Stack< T >::push_in_poisoned_room ( Args &&...  args)
inlineprivate

◆ release()

template<class T >
void Aleph::Dfs_Stack< T >::release ( )
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().

Referenced by TEST_F(), and TEST_F().

◆ set_room()

◆ size()

template<class T >
size_t Aleph::Dfs_Stack< T >::size ( ) const
inlinenoexcept

◆ top()

template<class T >
T & Aleph::Dfs_Stack< T >::top ( )
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().

Member Data Documentation

◆ base

◆ Initial_Capacity

template<class T >
constexpr size_t Aleph::Dfs_Stack< T >::Initial_Capacity = sizeof(T) < 1000 ? 1000 / sizeof(T) : 1
staticconstexprprivate

Definition at line 247 of file tpl_dfs_stack.H.

Referenced by Aleph::Dfs_Stack< T >::enlarge().

◆ limit

◆ room

◆ room_bytes

◆ Second_Capacity

template<class T >
constexpr size_t Aleph::Dfs_Stack< T >::Second_Capacity = 256
staticconstexprprivate

Definition at line 251 of file tpl_dfs_stack.H.

Referenced by Aleph::Dfs_Stack< T >::enlarge().

◆ top_ptr


The documentation for this class was generated from the following file: