From 6a418e1166a2075036e88773f2778a03a628b35c Mon Sep 17 00:00:00 2001 From: burgholzer Date: Mon, 16 Oct 2023 11:57:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20better=20templating=20`Edge`=20-?= =?UTF-8?q?>=20`Edge`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- include/dd/Export.hpp | 56 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/include/dd/Export.hpp b/include/dd/Export.hpp index ec8da35ad..692fcbb2a 100644 --- a/include/dd/Export.hpp +++ b/include/dd/Export.hpp @@ -154,9 +154,9 @@ inline std::string conditionalFormat(const Complex& a, return ss.str(); } -template -static std::ostream& header(const Edge& e, std::ostream& os, bool edgeLabels, - bool formatAsPolar = true) { +template +static std::ostream& header(const Edge& e, std::ostream& os, + bool edgeLabels, bool formatAsPolar = true) { os << "digraph \"DD\" {graph[];node[shape=plain];edge[arrowhead=none]\n"; os << "root [label=\"\",shape=point,style=invis]\n"; os << "t [label=< -static std::ostream& coloredHeader(const Edge& e, std::ostream& os, +template +static std::ostream& coloredHeader(const Edge& e, std::ostream& os, bool edgeLabels, bool formatAsPolar = true) { os << "digraph \"DD\" {graph[];node[shape=plain];edge[arrowhead=none]\n"; os << "root [label=\"\",shape=point,style=invis]\n"; @@ -210,8 +210,8 @@ static std::ostream& coloredHeader(const Edge& e, std::ostream& os, os << "]\n"; return os; } -template -static std::ostream& memoryHeader(const Edge& e, std::ostream& os, +template +static std::ostream& memoryHeader(const Edge& e, std::ostream& os, bool edgeLabels) { os << "digraph \"DD\" {graph[];node[shape=plain];edge[arrowhead=none]\n"; os << "root [label=\"\",shape=point,style=invis]\n"; @@ -412,8 +412,8 @@ classicNode(const vEdge& e, std::ostream& os, bool formatAsPolar = true) { << "\"]\n"; return os; } -template -static std::ostream& memoryNode(const Edge& e, std::ostream& os) { +template +static std::ostream& memoryNode(const Edge& e, std::ostream& os) { constexpr std::size_t n = std::tuple_size_ve)>; auto nodelabel = (reinterpret_cast(e.p) & 0x001fffffU) >> 1U; // this allows for 2^20 (roughly 1e6) unique nodes @@ -426,7 +426,7 @@ static std::ostream& memoryNode(const Edge& e, std::ostream& os) { for (std::size_t i = 0; i < n; ++i) { os << "e[i].w.toString(false, 4) << "\">"; - if (e.p->e[i] == Edge::zero) { + if (e.p->e[i] == Edge::zero) { os << " 0 " ""; } else { @@ -593,8 +593,8 @@ coloredEdge(const vEdge& from, const vEdge& to, std::uint16_t idx, return os; } -template -static std::ostream& memoryEdge(const Edge& from, const Edge& to, +template +static std::ostream& memoryEdge(const Edge& from, const Edge& to, std::uint16_t idx, std::ostream& os, bool edgeLabels = false) { auto fromlabel = @@ -644,8 +644,8 @@ static std::ostream& memoryEdge(const Edge& from, const Edge& to, return os; } -template -static void toDot(const Edge& e, std::ostream& os, bool colored = true, +template +static void toDot(const Edge& e, std::ostream& os, bool colored = true, bool edgeLabels = false, bool classic = false, bool memory = false, bool formatAsPolar = true) { std::ostringstream oss{}; @@ -661,7 +661,7 @@ static void toDot(const Edge& e, std::ostream& os, bool colored = true, std::unordered_set nodes{}; - auto priocmp = [](const Edge* left, const Edge* right) { + auto priocmp = [](const Edge* left, const Edge* right) { if (left->p == nullptr) { return right->p != nullptr; } @@ -671,7 +671,8 @@ static void toDot(const Edge& e, std::ostream& os, bool colored = true, return left->p->v < right->p->v; }; - std::priority_queue, decltype(priocmp)> + std::priority_queue*, std::vector*>, + decltype(priocmp)> q(priocmp); q.push(&e); @@ -729,11 +730,11 @@ static void toDot(const Edge& e, std::ostream& os, bool colored = true, os << oss.str() << std::flush; } -template +template [[maybe_unused]] static void -export2Dot(Edge basic, const std::string& outputFilename, bool colored = true, - bool edgeLabels = false, bool classic = false, bool memory = false, - bool show = true, bool formatAsPolar = true) { +export2Dot(Edge basic, const std::string& outputFilename, + bool colored = true, bool edgeLabels = false, bool classic = false, + bool memory = false, bool show = true, bool formatAsPolar = true) { std::ofstream init(outputFilename); toDot(basic, init, colored, edgeLabels, classic, memory, formatAsPolar); init.close(); @@ -926,8 +927,9 @@ static void serializeMatrix(const mEdge& basic, std::int64_t& idx, std::unordered_set visited{}; serializeMatrix(basic, idx, nodeIndex, visited, os, writeBinary); } -template -static void serialize(const Edge& basic, const std::string& outputFilename, +template +static void serialize(const Edge& basic, + const std::string& outputFilename, bool writeBinary = false) { std::ofstream ofs = std::ofstream(outputFilename, std::ios::binary); @@ -938,10 +940,10 @@ static void serialize(const Edge& basic, const std::string& outputFilename, serialize(basic, ofs, writeBinary); } -template -static void exportEdgeWeights(const Edge& edge, std::ostream& stream) { +template +static void exportEdgeWeights(const Edge& edge, std::ostream& stream) { struct Priocmp { - bool operator()(const Edge* left, const Edge* right) { + bool operator()(const Edge* left, const Edge* right) { if (left->p == nullptr) { return right->p != nullptr; } @@ -956,7 +958,9 @@ static void exportEdgeWeights(const Edge& edge, std::ostream& stream) { std::unordered_set nodes{}; - std::priority_queue, Priocmp> q; + std::priority_queue*, std::vector*>, + Priocmp> + q; q.push(&edge); // bfs until finished