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

Extract tree topology: node indexing, adjacency, parent, order. 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.
 
size_t size () const noexcept
 Returns number of nodes.
 
Noderoot () const noexcept
 Returns root node pointer.
 
size_t id_of (Node *node) const
 Returns internal ID of a node.
 
Nodenode_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 GTgraph_ = nullptr
 Source graph.
 
SA sa_
 Arc filter.
 
Noderoot_ = 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<class GT, class SA>
class Aleph::tree_dp_detail::Tree_Topology< GT, SA >

Extract tree topology: node indexing, adjacency, parent, order.

This class preprocesses a graph tree to provide efficient access to parent-child relations and traversal orders.

Template Parameters
GTGraph type.
SAArc filter.

Definition at line 77 of file Tree_DP.H.

Member Typedef Documentation

◆ Arc

Arc type.

Definition at line 81 of file Tree_DP.H.

◆ Node

Node type.

Definition at line 80 of file Tree_DP.H.

Constructor & Destructor Documentation

◆ Tree_Topology()

template<class GT , class 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 251 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().

Member Function Documentation

◆ build_adjacency()

◆ build_order()

◆ children()

template<class GT , class 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 283 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<class GT , class SA >
size_t Aleph::tree_dp_detail::Tree_Topology< GT, SA >::id_of ( Node node) const
inline

◆ index_nodes()

◆ node_of()

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

◆ nodes()

template<class GT , class 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 301 of file Tree_DP.H.

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

◆ parent()

template<class GT , class 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 289 of file Tree_DP.H.

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

◆ post_order()

template<class GT , class 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 295 of file Tree_DP.H.

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

◆ root()

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

Returns root node pointer.

Definition at line 263 of file Tree_DP.H.

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

◆ size()

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

Returns number of nodes.

Definition at line 260 of file Tree_DP.H.

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

Member Data Documentation

◆ children_

◆ graph_

◆ id_to_node_

◆ n_

◆ node_to_id_

◆ NONE

template<class GT , class 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 84 of file Tree_DP.H.

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

◆ order_

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

Post-order traversal (leaves first).

Definition at line 96 of file Tree_DP.H.

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

◆ parent_

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

◆ root_

◆ sa_

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

Arc filter.

Definition at line 88 of file Tree_DP.H.

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


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