[PATCH] D151550: DirectedGraph: Add a constructor that takes a list of Nodes.
Johannes Reifferscheid via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 26 03:27:36 PDT 2023
jreiffers updated this revision to Diff 526008.
jreiffers marked an inline comment as done.
jreiffers added a comment.
Add test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151550/new/
https://reviews.llvm.org/D151550
Files:
llvm/include/llvm/ADT/DirectedGraph.h
llvm/unittests/ADT/DirectedGraphTest.cpp
Index: llvm/unittests/ADT/DirectedGraphTest.cpp
===================================================================
--- llvm/unittests/ADT/DirectedGraphTest.cpp
+++ llvm/unittests/ADT/DirectedGraphTest.cpp
@@ -243,8 +243,16 @@
EXPECT_TRUE(EL.empty());
}
-TEST(DirectedGraphTest, SCC) {
+TEST(DirectedGraphTest, ConstructFromList) {
+ DGTestNode N1, N2;
+ DGTestGraph::NodeListTy nodes{&N1, &N2};
+ DGTestGraph graph(std::move(nodes));
+ EXPECT_FALSE(DG.addNode(N1));
+ EXPECT_FALSE(DG.addNode(N2));
+}
+
+TEST(DirectedGraphTest, SCC) {
DGTestGraph DG;
DGTestNode N1, N2, N3, N4;
DGTestEdge E1(N1), E2(N2), E3(N3), E4(N4);
Index: llvm/include/llvm/ADT/DirectedGraph.h
===================================================================
--- llvm/include/llvm/ADT/DirectedGraph.h
+++ llvm/include/llvm/ADT/DirectedGraph.h
@@ -172,9 +172,9 @@
/// Each edge contains the target node it connects to.
template <class NodeType, class EdgeType> class DirectedGraph {
protected:
- using NodeListTy = SmallVector<NodeType *, 10>;
using EdgeListTy = SmallVector<EdgeType *, 10>;
public:
+ using NodeListTy = SmallVector<NodeType *, 10>;
using iterator = typename NodeListTy::iterator;
using const_iterator = typename NodeListTy::const_iterator;
using DGraphType = DirectedGraph<NodeType, EdgeType>;
@@ -183,6 +183,7 @@
explicit DirectedGraph(NodeType &N) : Nodes() { addNode(N); }
DirectedGraph(const DGraphType &G) : Nodes(G.Nodes) {}
DirectedGraph(DGraphType &&RHS) : Nodes(std::move(RHS.Nodes)) {}
+ explicit DirectedGraph(NodeListTy Nodes) : Nodes(std::move(Nodes)) {}
DGraphType &operator=(const DGraphType &G) {
Nodes = G.Nodes;
return *this;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151550.526008.patch
Type: text/x-patch
Size: 1700 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230526/d0c01649/attachment.bin>
More information about the llvm-commits
mailing list