53#ifndef TOPOLOGICAL_SORT_H
54#define TOPOLOGICAL_SORT_H
79template <AlephGraph
GT,
99 :
sa(__sa),
gptr(nullptr) { }
121 for (;
it.has_curr();
it.next_ne())
137 template <
template <
class>
class List>
141 assert(
gptr !=
nullptr);
157 f = &frames.
push(tgt,
sa);
188 template <
template <
class>
class List>
202 auto curr = it.get_current_node_ne();
216 perform<DynDlist>(g).swap(list);
239template <AlephGraph
GT,
252 :
sa(
std::move(__sa)) { }
275 template <
template <
class>
class List>
288 for (
auto it = g.
get_node_it(); it.has_curr(); it.next_ne())
290 auto p = it.get_current_node_ne();
304 for (Itor<GT, SA> it(p,
sa); it.has_curr(); it.next_ne())
306 auto tgt = it.get_tgt_node_ne();
332 template <
template <
class>
class RankList =
DynList,
334 [[nodiscard]] RankList<List<typename GT::Node*>>
ranks(
const GT & g)
339 for (
typename GT::Node_Iterator i(g); i.has_curr(); i.next_ne())
340 for (Itor<GT, SA> j(i.get_current_node_ne(),
sa);
341 j.has_curr(); j.next_ne())
346 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne())
348 auto p = it.get_current_node_ne();
353 RankList<List<typename GT::Node*>>
ranks;
365 for (Itor<GT, SA> it(p,
sa); it.has_curr(); it.next_ne())
367 auto tgt = it.get_tgt_node_ne();
373 ranks.append(std::move(rank));
387 auto result = this->ranks<>(g);
389 for (
auto it = result.get_it(); it.has_curr(); it.next_ne())
390 list.append(std::move(it.get_curr()));
399 this->ranks<DynList>(g).swap(list);
408 this->perform<DynDlist>(g).swap(list);
C++20 concepts for the protocol shared by graph algorithms.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Stack of the frames of a depth-first search that does not recurse.
T & push(Args &&...args)
Builds a frame on top of the stack.
bool is_empty() const noexcept
Whether the stack has no frames.
T & top() noexcept
The top frame; the stack must not be empty.
void pop() noexcept
Destroys the top frame; the stack must not be empty.
void append(Dlink *node) noexcept
Insert node before this.
void insert(Dlink *node) noexcept
Insert node after this.
Node belonging to a double circular linked list with header node.
Dynamic doubly linked list with O(1) size and bidirectional access.
Dynamic queue of elements of generic type T based on single linked list.
T & put(const T &data)
The type of element.
T get()
Remove the oldest item of the queue.
void swap(DynListQueue &__q) noexcept
Swap this with __q in constant time.
bool is_empty() const noexcept
Return true if this is empty.
Doubly-linked list (defined in tpl_dynList.H).
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
A filter that an algorithm object keeps: one given as an lvalue is used where it is,...
Filtered iterator for outcoming arcs of a node.
Computes topological ordering using breadth-first search (Kahn's algorithm).
void operator()(const GT &g, DynList< DynList< typename GT::Node * > > &list)
Operator() overload returning ranks as DynList of DynList.
Q_Topological_Sort(SA &&__sa=SA())
Constructor with rvalue arc filter.
Q_Topological_Sort(SA &__sa)
Constructor with lvalue arc filter.
void operator()(const GT &g, DynDlist< typename GT::Node * > &list)
Operator() overload for backward compatibility (flat list).
void operator()(const GT &g, DynDlist< DynList< typename GT::Node * > > &list)
Operator() overload returning ranks as DynDlist of DynList.
List< typename GT::Node * > perform(const GT &g)
Compute topological ordering using BFS (Kahn's algorithm).
RankList< List< typename GT::Node * > > ranks(const GT &g)
Compute rank-based topological ordering.
Computes topological ordering using depth-first search.
List< typename GT::Node * > perform(const GT &g)
Compute topological ordering using DFS.
Topological_Sort(SA &&__sa=SA())
Constructor with rvalue arc filter.
void operator()(const GT &g, DynDlist< typename GT::Node * > &list)
Operator() overload for backward compatibility.
Topological_Sort(SA &__sa)
Constructor with lvalue arc filter.
size_t topological_sort(typename GT::Node *curr, List< typename GT::Node * > &list)
Helper for DFS-based topological sort.
void reset_bit_nodes(int bit) const noexcept
Reset bit to zero for all the nodes of graph.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
void reset_counter_nodes() const noexcept
Reset all the counters to zero for all the nodes of graph.
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
#define NODE_COUNTER(p)
Get the counter of a node.
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
#define NODE_BITS(p)
Get the control bits of a node.
#define ALEPH_FLATTEN
[[gnu::flatten]], or nothing where it would only make the compilation slower.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
void next_ne() noexcept(noexcept(std::declval< Aleph::const_iterator_t< HeadC > & >().next_ne()) and noexcept(std::declval< ZipIterator< TailC... > & >().next_ne()))
Advance all underlying iterators (unchecked variant).
Filtered iterator on all the arcs of a graph.
Default filter for filtered iterators on arcs.
void next_arc() noexcept(noexcept(it.next_ne()))
Frame(typename GT::Node *p, SA &sa)
Stack of the frames of a depth-first search that does not recurse.
Dynamic queue implementation based on linked lists.
Generic graph and digraph implementations.