From fffa39bbbe7c0e2b7ef64d8ff143c6003333cbaf Mon Sep 17 00:00:00 2001 From: David Date: Sun, 13 Feb 2022 17:33:55 +0800 Subject: [PATCH] refactor: change sequence/graph vertex name to edge (#31) Co-authored-by: ArthurSonzogni --- src/boost | 1 - src/translator/graph_planar/CMakeLists.txt | 8 ++++++-- src/translator/sequence/Graph.cpp | 14 +++++++------- src/translator/sequence/Graph.hpp | 10 +++++----- src/translator/sequence/Sequence.cpp | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) delete mode 120000 src/boost diff --git a/src/boost b/src/boost deleted file mode 120000 index 2d6e0ad..0000000 --- a/src/boost +++ /dev/null @@ -1 +0,0 @@ -/usr/include/boost \ No newline at end of file diff --git a/src/translator/graph_planar/CMakeLists.txt b/src/translator/graph_planar/CMakeLists.txt index c5468eb..52fdd36 100644 --- a/src/translator/graph_planar/CMakeLists.txt +++ b/src/translator/graph_planar/CMakeLists.txt @@ -1,5 +1,7 @@ ANTLR(GraphPlanar.g4) +find_package(Boost COMPONENTS graph) + add_library(translator_graph_planar STATIC GraphPlanarLexer.cpp GraphPlanarParser.cpp @@ -10,6 +12,8 @@ else() target_compile_options(translator_graph_planar PRIVATE "-Wno-attributes") endif() -target_link_libraries(translator_graph_planar PRIVATE diagon_base) -target_link_libraries(translator_graph_planar PRIVATE antlr4_static) +target_link_libraries(translator_graph_planar + PRIVATE diagon_base + PRIVATE antlr4_static + PRIVATE Boost::graph) target_set_common(translator_graph_planar) diff --git a/src/translator/sequence/Graph.cpp b/src/translator/sequence/Graph.cpp index 8196f0f..6b5b1a7 100644 --- a/src/translator/sequence/Graph.cpp +++ b/src/translator/sequence/Graph.cpp @@ -10,8 +10,8 @@ namespace graph { -Vertex::Vertex(const Node& from, const Node& to) : from(from), to(to) {} -Vertex::Vertex(const Message& message) +Edge::Edge(const Node& from, const Node& to) : from(from), to(to) {} +Edge::Edge(const Message& message) : from({message.from, message.id}), to({message.to, message.id}) {} bool operator<(const Node& a, const Node& b) { @@ -22,7 +22,7 @@ bool operator<(const Node& a, const Node& b) { return a.message < b.message; } -bool operator<(const Vertex& a, const Vertex& b) { +bool operator<(const Edge& a, const Edge& b) { if (a.from < b.from) return true; if (b.from < a.from) @@ -30,7 +30,7 @@ bool operator<(const Vertex& a, const Vertex& b) { return a.to < b.to; } -using Graph = std::set; +using Graph = std::set; std::vector FindTopologicalOrder(const Graph& graph) { std::map weight; @@ -38,9 +38,9 @@ std::vector FindTopologicalOrder(const Graph& graph) { int iteration = 0; while (work_to_do) { work_to_do = false; - for (const auto& vertex : graph) { - if (weight[vertex.to] <= weight[vertex.from]) { - weight[vertex.to] = weight[vertex.from] + 1; + for (const auto& edge : graph) { + if (weight[edge.to] <= weight[edge.from]) { + weight[edge.to] = weight[edge.from] + 1; work_to_do = true; } } diff --git a/src/translator/sequence/Graph.hpp b/src/translator/sequence/Graph.hpp index 5244ae9..b97e750 100644 --- a/src/translator/sequence/Graph.hpp +++ b/src/translator/sequence/Graph.hpp @@ -19,18 +19,18 @@ struct Node { int message; }; -struct Vertex { +struct Edge { Node from; Node to; - Vertex(const Node& from, const Node& to); - Vertex(const Message& message); + Edge(const Node& from, const Node& to); + Edge(const Message& message); }; -using Graph = std::set; +using Graph = std::set; bool operator<(const Node& a, const Node& b); -bool operator<(const Vertex& a, const Vertex& b); +bool operator<(const Edge& a, const Edge& b); std::vector FindTopologicalOrder(const Graph& graph); } // namespace graph diff --git a/src/translator/sequence/Sequence.cpp b/src/translator/sequence/Sequence.cpp index 0e4c41b..b7b6fab 100644 --- a/src/translator/sequence/Sequence.cpp +++ b/src/translator/sequence/Sequence.cpp @@ -591,7 +591,7 @@ void Sequence::LayoutComputeMessagesPositions() { if (cut.count(message.id)) { graph::Node from = {actor_index[message.from], message.id}; graph::Node to = {actor_index[message.to], message.id}; - graph.insert(graph::Vertex(from, to)); + graph.insert(graph::Edge(from, to)); } } std::set started_message;