diff options
author | Thomas Lively <tlively@google.com> | 2024-09-03 09:21:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-03 09:21:07 -0700 |
commit | b7cdb8c2110dff5a9b096d766dac04cd8ec04cc9 (patch) | |
tree | 401a90a9b28a625638c2bc9c6f687bb3662862bc /src/support/topological_orders.cpp | |
parent | 871ff0d4f910b565c15f82e8f3c9aa769b01d286 (diff) | |
download | binaryen-b7cdb8c2110dff5a9b096d766dac04cd8ec04cc9.tar.gz binaryen-b7cdb8c2110dff5a9b096d766dac04cd8ec04cc9.tar.bz2 binaryen-b7cdb8c2110dff5a9b096d766dac04cd8ec04cc9.zip |
[NFC] Change topological sort utilities to functions (#6889)
Previously they were structs and their results were accessed with
`operator*()`, but that was unnecessarily complicated and could lead to
problems with temporary lifetimes being too short. Simplify the
utilities by making them functions. This also allows the wrapper
templates to infer the proper element types automatically.
Diffstat (limited to 'src/support/topological_orders.cpp')
-rw-r--r-- | src/support/topological_orders.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/support/topological_orders.cpp b/src/support/topological_orders.cpp index 0536d4ed9..aeec95d18 100644 --- a/src/support/topological_orders.cpp +++ b/src/support/topological_orders.cpp @@ -78,8 +78,7 @@ TopologicalOrders::Selector::advance(TopologicalOrders& ctx) { return select(ctx); } -TopologicalOrders::TopologicalOrders( - const std::vector<std::vector<size_t>>& graph, SelectionMethod method) +TopologicalOrders::TopologicalOrders(const Graph& graph, SelectionMethod method) : graph(graph), indegrees(graph.size()), buf(graph.size()) { if (graph.size() == 0) { return; @@ -145,4 +144,16 @@ size_t TopologicalOrders::popChoice() { return choice; } +namespace TopologicalSort { + +std::vector<size_t> sort(const Graph& graph) { + return *TopologicalOrders(graph, TopologicalOrders::InPlace); +} + +std::vector<size_t> minSort(const Graph& graph) { + return *TopologicalOrders(graph, TopologicalOrders::MinHeap); +} + +} // namespace TopologicalSort + } // namespace wasm |