Make SCC inherit parent constructor to avoid duplicate code
This commit is contained in:
15
graph/scc.h
15
graph/scc.h
@@ -1,18 +1,19 @@
|
|||||||
#ifndef SCC_H_
|
#ifndef SCC_H_
|
||||||
#define SCC_H_
|
#define SCC_H_
|
||||||
|
|
||||||
#include "graph.h"
|
#include "digraph.h"
|
||||||
|
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
|
||||||
namespace graph {
|
namespace graph {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class SCC : public Graph<T> {
|
class SCC : public Digraph<T> {
|
||||||
public:
|
public:
|
||||||
SCC() = default;
|
SCC() = default;
|
||||||
|
|
||||||
SCC(std::map<T, std::set<T>> scc);
|
SCC(std::map<T, std::set<T>> scc)
|
||||||
|
: Digraph<T>::Digraph(scc) { proxy = scc.begin()->first; }
|
||||||
|
|
||||||
//
|
//
|
||||||
T representative() { return proxy; };
|
T representative() { return proxy; };
|
||||||
@@ -23,14 +24,6 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
SCC<T>::SCC(std::map<T, std::set<T>> scc) {
|
|
||||||
Graph<T>::adjMatrix = scc;
|
|
||||||
auto kv = std::views::keys(Graph<T>::adjMatrix);
|
|
||||||
Graph<T>::vertices = std::set<T>{ kv.begin(), kv.end() };
|
|
||||||
proxy = scc.begin()->first;
|
|
||||||
}
|
|
||||||
|
|
||||||
}; // namespace graph
|
}; // namespace graph
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user