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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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