Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::tree_dp_detail::Tree_Topology< GT, SA > Class Template Reference

Pre-processes and extracts tree topology from a graph. More...

#include <Tree_DP.H>

Inheritance diagram for Aleph::tree_dp_detail::Tree_Topology< GT, SA >:
[legend]
Collaboration diagram for Aleph::tree_dp_detail::Tree_Topology< GT, SA >:
[legend]

Public Types

using Node = typename GT::Node
 Node type.
 
using Arc = typename GT::Arc
 Arc type.
 

Public Member Functions

 Tree_Topology (const GT &g, Node *root, SA sa=SA())
 Preprocess tree topology.
 
 Tree_Topology (const Tree_Topology &other)=default
 Copy the topology of another tree.
 
 Tree_Topology (Tree_Topology &&other) noexcept(std::is_nothrow_move_constructible_v< SA >)
 Take the topology of another tree, which is left empty.
 
Tree_Topology & operator= (const Tree_Topology &other)=default
 Copy the topology of another tree.
 
Tree_Topology & operator= (Tree_Topology &&other) noexcept(noexcept(swap(other)))
 Exchange this topology with another, which is left with the previous topology of this one.
 
void swap (Tree_Topology &other) noexcept(std::is_nothrow_swappable_v< SA >)
 Exchange in O(1) this topology and another.
 
size_t size () const noexcept
 Returns number of nodes.
 
Node * root () const noexcept
 Returns root node pointer.
 
size_t id_of (Node *node) const
 Returns internal ID of a node.
 
Node * node_of (size_t id) const
 Returns node pointer for a given ID.
 
const Array< size_t > & children (size_t id) const
 Returns children IDs of a node.
 
size_t parent (size_t id) const noexcept
 Returns parent ID of a node.
 
const Array< size_t > & post_order () const noexcept
 Returns post-order traversal (leaves first, root last).
 
const Array< Node * > & nodes () const noexcept
 Returns all node pointers indexed by ID.
 

Static Public Attributes

static constexpr size_t NONE = std::numeric_limits<size_t>::max()
 Sentinel for null/none parent or id.
 

Private Member Functions

void index_nodes ()
 Assign unique IDs to nodes and validate the root.
 
void build_adjacency ()
 Build undirected adjacency list and verify tree properties.
 
void build_order ()
 BFS/DFS traversal to establish parent-child relations and order.
 

Private Attributes

const GT * graph_ = nullptr
 Source graph.
 
SA sa_
 Arc filter.
 
Node * root_ = nullptr
 Tree root.
 
size_t n_ = 0
 Number of nodes.
 
Array< Node * > id_to_node_
 Mapping from id to node pointer.
 
MapOLhash< Node *, size_t > node_to_id_
 Mapping from node pointer to id.
 
Array< Array< size_t > > children_
 Children list in the rooted tree.
 
Array< size_t > parent_
 Parent id for each node.
 
Array< size_t > order_
 Post-order traversal (leaves first).
 

Detailed Description

template<AlephGraph GT, ArcFilter< GT > SA>
class Aleph::tree_dp_detail::Tree_Topology< GT, SA >

Pre-processes and extracts tree topology from a graph.

Verifies tree properties, assigns internal IDs to nodes, and establishes parent-child relationships for a given root.

Template Parameters
GTGraph type.
SAArc filter.

Definition at line 83 of file Tree_DP.H.

Member Typedef Documentation

◆ Arc

template<AlephGraph GT, ArcFilter< GT > SA>
using Aleph::tree_dp_detail::Tree_Topology< GT, SA >::Arc = typename GT::Arc

Arc type.

Definition at line 89 of file Tree_DP.H.

◆ Node

template<AlephGraph GT, ArcFilter< GT > SA>
using Aleph::tree_dp_detail::Tree_Topology< GT, SA >::Node = typename GT::Node

Node type.

Definition at line 88 of file Tree_DP.H.

Constructor & Destructor Documentation

◆ Tree_Topology() [1/3]

template<AlephGraph GT, ArcFilter< GT > SA>
Aleph::tree_dp_detail::Tree_Topology< GT, SA >::Tree_Topology ( const GT &  g,
Node *  root,
SA  sa = SA() 
)
inline

Preprocess tree topology.

Parameters
[in]gThe graph tree.
[in]rootThe root node.
[in]saThe arc filter.
Exceptions
ah_domain_errorif not a tree or root not in graph.

Definition at line 258 of file Tree_DP.H.

References Aleph::tree_dp_detail::Tree_Topology< GT, SA >::build_adjacency(), Aleph::tree_dp_detail::Tree_Topology< GT, SA >::build_order(), and Aleph::tree_dp_detail::Tree_Topology< GT, SA >::index_nodes().

◆ Tree_Topology() [2/3]

template<AlephGraph GT, ArcFilter< GT > SA>
Aleph::tree_dp_detail::Tree_Topology< GT, SA >::Tree_Topology ( const Tree_Topology< GT, SA > &  other)
default

Copy the topology of another tree.

Parameters
[in]othertopology to copy.

◆ Tree_Topology() [3/3]

template<AlephGraph GT, ArcFilter< GT > SA>
Aleph::tree_dp_detail::Tree_Topology< GT, SA >::Tree_Topology ( Tree_Topology< GT, SA > &&  other)
inlinenoexcept

Take the topology of another tree, which is left empty.

The implicit move took the arrays and the map but copied the number of nodes: the moved-from topology then reported the old size, and node_of() passed its check and read an array that it no longer had.

Parameters
[in,out]othertopology to move from.

Definition at line 278 of file Tree_DP.H.

Member Function Documentation

◆ build_adjacency()

◆ build_order()

◆ children()

template<AlephGraph GT, ArcFilter< GT > SA>
const Array< size_t > & Aleph::tree_dp_detail::Tree_Topology< GT, SA >::children ( size_t  id) const
inline

Returns children IDs of a node.

Definition at line 353 of file Tree_DP.H.

References Aleph::tree_dp_detail::Tree_Topology< GT, SA >::children_.

Referenced by Aleph::tree_dp_detail::Tree_Topology< GT, SA >::build_order().

◆ id_of()

template<AlephGraph GT, ArcFilter< GT > SA>
size_t Aleph::tree_dp_detail::Tree_Topology< GT, SA >::id_of ( Node *  node) const
inline

◆ index_nodes()

◆ node_of()

template<AlephGraph GT, ArcFilter< GT > SA>
Node * Aleph::tree_dp_detail::Tree_Topology< GT, SA >::node_of ( size_t  id) const
inline

◆ nodes()

template<AlephGraph GT, ArcFilter< GT > SA>
const Array< Node * > & Aleph::tree_dp_detail::Tree_Topology< GT, SA >::nodes ( ) const
inlinenoexcept

Returns all node pointers indexed by ID.

Definition at line 371 of file Tree_DP.H.

References Aleph::tree_dp_detail::Tree_Topology< GT, SA >::id_to_node_.

◆ operator=() [1/2]

template<AlephGraph GT, ArcFilter< GT > SA>
Tree_Topology & Aleph::tree_dp_detail::Tree_Topology< GT, SA >::operator= ( const Tree_Topology< GT, SA > &  other)
default

Copy the topology of another tree.

Parameters
[in]othertopology to copy.
Returns
this topology.

◆ operator=() [2/2]

template<AlephGraph GT, ArcFilter< GT > SA>
Tree_Topology & Aleph::tree_dp_detail::Tree_Topology< GT, SA >::operator= ( Tree_Topology< GT, SA > &&  other)
inlinenoexcept

Exchange this topology with another, which is left with the previous topology of this one.

Parameters
[in,out]othertopology to move from.
Returns
this topology.

Definition at line 297 of file Tree_DP.H.

References Aleph::tree_dp_detail::Tree_Topology< GT, SA >::swap().

◆ parent()

template<AlephGraph GT, ArcFilter< GT > SA>
size_t Aleph::tree_dp_detail::Tree_Topology< GT, SA >::parent ( size_t  id) const
inlinenoexcept

Returns parent ID of a node.

Definition at line 359 of file Tree_DP.H.

References Aleph::tree_dp_detail::Tree_Topology< GT, SA >::parent_.

◆ post_order()

template<AlephGraph GT, ArcFilter< GT > SA>
const Array< size_t > & Aleph::tree_dp_detail::Tree_Topology< GT, SA >::post_order ( ) const
inlinenoexcept

Returns post-order traversal (leaves first, root last).

Definition at line 365 of file Tree_DP.H.

References Aleph::tree_dp_detail::Tree_Topology< GT, SA >::order_.

◆ root()

template<AlephGraph GT, ArcFilter< GT > SA>
Node * Aleph::tree_dp_detail::Tree_Topology< GT, SA >::root ( ) const
inlinenoexcept

Returns root node pointer.

Definition at line 332 of file Tree_DP.H.

References Aleph::tree_dp_detail::Tree_Topology< GT, SA >::root_.

◆ size()

template<AlephGraph GT, ArcFilter< GT > SA>
size_t Aleph::tree_dp_detail::Tree_Topology< GT, SA >::size ( ) const
inlinenoexcept

Returns number of nodes.

Definition at line 326 of file Tree_DP.H.

References Aleph::tree_dp_detail::Tree_Topology< GT, SA >::n_.

◆ swap()

Member Data Documentation

◆ children_

◆ graph_

◆ id_to_node_

◆ n_

◆ node_to_id_

◆ NONE

template<AlephGraph GT, ArcFilter< GT > SA>
constexpr size_t Aleph::tree_dp_detail::Tree_Topology< GT, SA >::NONE = std::numeric_limits<size_t>::max()
staticconstexpr

Sentinel for null/none parent or id.

Definition at line 92 of file Tree_DP.H.

Referenced by Aleph::tree_dp_detail::Tree_Topology< GT, SA >::build_order().

◆ order_

template<AlephGraph GT, ArcFilter< GT > SA>
Array<size_t> Aleph::tree_dp_detail::Tree_Topology< GT, SA >::order_
private

◆ parent_

template<AlephGraph GT, ArcFilter< GT > SA>
Array<size_t> Aleph::tree_dp_detail::Tree_Topology< GT, SA >::parent_
private

◆ root_

◆ sa_

template<AlephGraph GT, ArcFilter< GT > SA>
SA Aleph::tree_dp_detail::Tree_Topology< GT, SA >::sa_
private

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