//
//===----------------------------------------------------------------------===//
-#include <limits.h>
-#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/SCCIterator.h"
+#include "llvm/ADT/GraphTraits.h"
#include "gtest/gtest.h"
+#include <limits.h>
using namespace llvm;
NodeSubset() : Elements(0) {
assert(N <= sizeof(BitVector)*CHAR_BIT && "Graph too big!");
}
- /// NodeSubset - Copy constructor.
- NodeSubset(const NodeSubset &other) : Elements(other.Elements) {}
/// Comparison operators.
bool operator==(const NodeSubset &other) const {
// Return a pointer to it.
return FirstNode + i;
assert(false && "Dereferencing end iterator!");
- return 0; // Avoid compiler warning.
+ return nullptr; // Avoid compiler warning.
}
};
// create graphs for which every node has a self-edge.
#define NUM_NODES 4
#define NUM_GRAPHS (NUM_NODES * (NUM_NODES - 1))
+ typedef Graph<NUM_NODES> GT;
- /// GraphDescriptor - Enumerate all graphs using NUM_GRAPHS bits.
- unsigned GraphDescriptor = 0;
- assert(NUM_GRAPHS <= sizeof(unsigned) * CHAR_BIT && "Too many graphs!");
-
- do {
- typedef Graph<NUM_NODES> GT;
-
+ /// Enumerate all graphs using NUM_GRAPHS bits.
+ static_assert(NUM_GRAPHS < sizeof(unsigned) * CHAR_BIT, "Too many graphs!");
+ for (unsigned GraphDescriptor = 0; GraphDescriptor < (1U << NUM_GRAPHS);
+ ++GraphDescriptor) {
GT G;
// Add edges as specified by the descriptor.
GT::NodeSubset NodesInSomeSCC;
for (scc_iterator<GT> I = scc_begin(G), E = scc_end(G); I != E; ++I) {
- std::vector<GT::NodeType*> &SCC = *I;
+ const std::vector<GT::NodeType *> &SCC = *I;
// Get the nodes in this SCC as a NodeSubset rather than a vector.
GT::NodeSubset NodesInThisSCC;
// Finally, check that the nodes in some SCC are exactly those that are
// reachable from the initial node.
EXPECT_EQ(NodesInSomeSCC, G.NodesReachableFrom(0));
-
- ++GraphDescriptor;
- } while (GraphDescriptor && GraphDescriptor < (1U << NUM_GRAPHS));
+ }
}
}