Remove "using namespace" from headers and make single param constructors explicit

This commit is contained in:
stefiosif
2022-12-03 15:43:00 +02:00
parent d7e87e0956
commit 7c78bbd7ca
9 changed files with 13 additions and 30 deletions

View File

@@ -8,7 +8,7 @@ namespace algo {
template<typename T>
class DecrementalReachability {
public:
virtual ~DecrementalReachability() {};
virtual ~DecrementalReachability() = default;
// This method is implemented and executed by all roditty and zwick
// algorithms, it constructs the data structures used in other operations

View File

@@ -6,8 +6,6 @@
#include <utility>
using namespace graph;
namespace algo {
template<typename T>
@@ -15,7 +13,7 @@ class Frigioni : public DecrementalReachability<T> {
public:
Frigioni() = default;
Frigioni(Digraph<T> G) { this->G = G; }
explicit Frigioni(graph::Digraph<T> G) { this->G = G; }
// Initialize the decremental maintenance data structure for general graphs
void init() override;

View File

@@ -4,8 +4,6 @@
#include "algorithm/dynamic_reachability.h"
#include "algorithm/frigioni.h"
using namespace graph;
constexpr int threshold = 5;
namespace algo {
@@ -15,7 +13,7 @@ class HenzingerKing : public DynamicReachability<T> {
public:
HenzingerKing() = default;
HenzingerKing(Digraph<T> G) { this->G = G; }
explicit HenzingerKing(graph::Digraph<T> G) { this->G = G; }
// Initialize decremental maintenance data structure and the empty set S
void init() override;
@@ -57,7 +55,7 @@ bool HenzingerKing<T>::query(const T& u, const T& v) {
if (frigioni.query(u, v))
return true;
return std::any_of(S.begin(), S.end(),
return std::ranges::any_of(S.begin(), S.end(),
[&](const T& w) {
return In[w].adjList.contains(u) &&
Out[w].adjList.contains(v);

View File

@@ -6,8 +6,6 @@
#include <stack>
using namespace graph;
namespace algo {
template<typename T>
@@ -15,7 +13,7 @@ class Italiano : public DecrementalReachability<T> {
public:
Italiano() = default;
Italiano(Digraph<T> G) { this->G = G; }
explicit Italiano(graph::Digraph<T> G) { this->G = G; }
// Initialize the decremental maintenance data structure for DAGs
void init() override;

View File

@@ -4,8 +4,6 @@
#include "algorithm/dynamic_reachability.h"
#include "algorithm/italiano.h"
using namespace graph;
namespace algo {
template<typename T>
@@ -13,7 +11,7 @@ class King : public DynamicReachability<T> {
public:
King() = default;
King(Digraph<T> G) { this->G = G; }
explicit King(graph::Digraph<T> G) { this->G = G; }
// Initialize decremental maintenance data structures for DAGs for each
// vertex's in and out reachability trees
@@ -50,7 +48,7 @@ void King<T>::init() {
template<typename T>
bool King<T>::query(const T& u, const T& v) {
return std::any_of(this->G.vertices().begin(), this->G.vertices().end(),
return std::ranges::any_of(this->G.vertices().begin(), this->G.vertices().end(),
[&](const T& w) {
return In[w].query(w, u) && Out[w].query(w, v);
});

View File

@@ -5,8 +5,6 @@
#include "algorithm/tarjan.h"
#include "graph/breadth_first_tree.h"
using namespace graph;
namespace algo {
template<typename T>
@@ -14,7 +12,7 @@ class RodittyZwick : public DecrementalReachability<T> {
public:
RodittyZwick() = default;
RodittyZwick(Digraph<T> G) { this->G = G; }
explicit RodittyZwick(graph::Digraph<T> G) { this->G = G; }
//
void init() override;

View File

@@ -7,8 +7,6 @@
#include <vector>
#include <ranges>
using namespace graph;
namespace algo {
template<typename T>
@@ -16,7 +14,7 @@ class Tarjan {
public:
Tarjan() = default;
Tarjan(std::unordered_map<T, std::unordered_set<T>> adjList) : adjList(adjList) {}
explicit Tarjan(std::unordered_map<T, std::unordered_set<T>> adjList) : adjList(adjList) {}
//
auto execute();
@@ -27,7 +25,7 @@ private:
std::unordered_map<T, std::unordered_set<T>> adjList;
std::stack<T> S;
std::int16_t index = 0;
std::vector<SCC<T>> SCCs;
std::vector<graph::SCC<T>> SCCs;
T cid;
struct Vertex {

View File

@@ -11,7 +11,7 @@ class Digraph : public Graph<T> {
public:
Digraph() = default;
Digraph(std::unordered_map<T, std::unordered_set<T>> G);
explicit Digraph(std::unordered_map<T, std::unordered_set<T>> G);
// Return true if there is a path from u to v
bool contains(const T& u, const T& v);

View File

@@ -15,7 +15,7 @@ template<typename T> std::ostream& operator<<(std::ostream& os, Graph<T>& G);
template<typename T>
class Graph {
public:
~Graph();
virtual ~Graph() = default;
// Return true if there is a path from u to v
virtual bool contains(const T& u, const T& v) =0;
@@ -41,11 +41,6 @@ public:
friend std::ostream& operator<<<>(std::ostream& os, Graph<T>& G);
};
template<typename T>
Graph<T>::~Graph() {
adjList.clear();
}
template<typename T>
auto Graph<T>::vertices() {
return std::views::keys(adjList);
@@ -62,7 +57,7 @@ std::uint16_t Graph<T>::E() {
for (const auto& u : vertices()) {
edges += static_cast<std::uint16_t>(adjList[u].size());
}
return static_cast<std::uint16_t>(edges);
return edges;
}
template<typename T>