From b7cdb8c2110dff5a9b096d766dac04cd8ec04cc9 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Tue, 3 Sep 2024 09:21:07 -0700 Subject: [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. --- src/support/topological_orders.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/support/topological_orders.cpp') 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>& 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 sort(const Graph& graph) { + return *TopologicalOrders(graph, TopologicalOrders::InPlace); +} + +std::vector minSort(const Graph& graph) { + return *TopologicalOrders(graph, TopologicalOrders::MinHeap); +} + +} // namespace TopologicalSort + } // namespace wasm -- cgit v1.2.3