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

Computes topological ordering using depth-first search. More...

#include <topological_sort.H>

Collaboration diagram for Aleph::Topological_Sort< GT, Itor, SA >:
[legend]

Public Member Functions

 Topological_Sort (SA &&__sa=SA())
 Constructor with rvalue arc filter.
 
 Topological_Sort (SA &__sa)
 Constructor with lvalue arc filter.
 
template<template< class > class List>
List< typename GT::Node * > perform (const GT &g)
 Compute topological ordering using DFS.
 
void operator() (const GT &g, DynDlist< typename GT::Node * > &list)
 Operator() overload for backward compatibility.
 

Private Member Functions

template<template< class > class List>
void topological_sort (typename GT::Node *curr, List< typename GT::Node * > &list)
 Recursive helper for DFS-based topological sort.
 

Private Attributes

SAsa
 
const GTgptr
 

Detailed Description

template<class GT, template< typename, class > class Itor = Out_Iterator, class SA = Dft_Show_Arc<GT>>
class Aleph::Topological_Sort< GT, Itor, SA >

Computes topological ordering using depth-first search.

This class performs topological sorting by recursively visiting nodes in depth-first order and inserting them in postfix order (after all successors have been visited).

The resulting order is a valid topological ordering where for every directed edge (u, v), u appears before v in the list.

Template Parameters
GTThe directed graph type.
ItorIterator type for traversing outgoing arcs (default: Out_Iterator).
SAArc filter/selector (default: Dft_Show_Arc<GT>).

Definition at line 78 of file topological_sort.H.

Constructor & Destructor Documentation

◆ Topological_Sort() [1/2]

template<class GT , template< typename, class > class Itor = Out_Iterator, class SA = Dft_Show_Arc<GT>>
Aleph::Topological_Sort< GT, Itor, SA >::Topological_Sort ( SA &&  __sa = SA())
inline

Constructor with rvalue arc filter.

Parameters
__saArc filter/selector (moved).

Definition at line 88 of file topological_sort.H.

◆ Topological_Sort() [2/2]

template<class GT , template< typename, class > class Itor = Out_Iterator, class SA = Dft_Show_Arc<GT>>
Aleph::Topological_Sort< GT, Itor, SA >::Topological_Sort ( SA __sa)
inline

Constructor with lvalue arc filter.

Parameters
__saArc filter/selector (referenced).

Definition at line 94 of file topological_sort.H.

Member Function Documentation

◆ operator()()

template<class GT , template< typename, class > class Itor = Out_Iterator, class SA = Dft_Show_Arc<GT>>
void Aleph::Topological_Sort< GT, Itor, SA >::operator() ( const GT g,
DynDlist< typename GT::Node * > &  list 
)
inline

Operator() overload for backward compatibility.

Parameters
gThe directed acyclic graph.
listOutput list to receive the topological ordering.

Definition at line 163 of file topological_sort.H.

References Aleph::maps(), and Aleph::DynList< T >::swap().

◆ perform()

template<class GT , template< typename, class > class Itor = Out_Iterator, class SA = Dft_Show_Arc<GT>>
template<template< class > class List>
List< typename GT::Node * > Aleph::Topological_Sort< GT, Itor, SA >::perform ( const GT g)
inline

Compute topological ordering using DFS.

Performs depth-first traversal of the graph, inserting nodes in postfix order to produce a valid topological ordering.

Template Parameters
ListContainer type for the result (e.g., DynList, DynDlist).
Parameters
gThe directed acyclic graph.
Returns
A list of nodes in topological order.
Exceptions
std::bad_allocIf memory allocation fails.
Note
This function does not verify that g is acyclic. If g contains cycles, the result is undefined.

Definition at line 139 of file topological_sort.H.

References Aleph::Depth_First, GraphCommon< GT, Node, Arc >::get_node_it(), GraphCommon< GT, Node, Arc >::get_num_nodes(), Aleph::Topological_Sort< GT, Itor, SA >::gptr, IS_NODE_VISITED, Aleph::maps(), GraphCommon< GT, Node, Arc >::reset_bit_nodes(), Aleph::HTList::size(), and Aleph::Topological_Sort< GT, Itor, SA >::topological_sort().

◆ topological_sort()

template<class GT , template< typename, class > class Itor = Out_Iterator, class SA = Dft_Show_Arc<GT>>
template<template< class > class List>
void Aleph::Topological_Sort< GT, Itor, SA >::topological_sort ( typename GT::Node curr,
List< typename GT::Node * > &  list 
)
inlineprivate

Member Data Documentation

◆ gptr

template<class GT , template< typename, class > class Itor = Out_Iterator, class SA = Dft_Show_Arc<GT>>
const GT* Aleph::Topological_Sort< GT, Itor, SA >::gptr
private

◆ sa

template<class GT , template< typename, class > class Itor = Out_Iterator, class SA = Dft_Show_Arc<GT>>
SA& Aleph::Topological_Sort< GT, Itor, SA >::sa
private

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