P4C
The P4 Compiler
Loading...
Searching...
No Matches
scc_toposort.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_COMMON_SCC_TOPOSORT_H_
20#define BACKENDS_TOFINO_BF_P4C_COMMON_SCC_TOPOSORT_H_
21
22#include <ostream>
23#include <unordered_map>
24#include <unordered_set>
25#include <vector>
26
27// SccTopoSorter is an opinionated non-boost implementation topological sort algorithm
28// that supports directed graph with strongly connected components.
30 public:
31 using Graph = std::unordered_map<int, std::unordered_set<int>>;
32
33 private:
34 int n_nodes_i = 0;
35 Graph graph_i;
36
37 public:
39 int new_node();
40
43 void add_dep(int a, int b);
44
48 //
53 //
59 //
64 std::unordered_map<int, int> scc_topo_sort() const;
65
66 private:
67 void validate_node_id(int i) const;
68};
69
70#endif /* BACKENDS_TOFINO_BF_P4C_COMMON_SCC_TOPOSORT_H_ */
Definition scc_toposort.h:29
int new_node()
create a new node and return a new node_id, starting from 1.
Definition common/scc_toposort.cpp:135
void add_dep(int a, int b)
Definition common/scc_toposort.cpp:150
std::unordered_map< int, int > scc_topo_sort() const
Definition common/scc_toposort.cpp:156