#ifndef NK_COMPONENT_H #define NK_COMPONENT_H #include "rust/cxx.h" #include "graph_event.h" #include #include #include #include #include #include #include namespace NetworKit { using namespace std; inline unique_ptr NewBiconnectedComponents(const Graph &G) { return make_unique(G); } inline void BiconnectedComponentsGetComponentSizes(const BiconnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getComponentSizes()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void BiconnectedComponentsGetComponents(const BiconnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { node i = 0; for (auto &&block : algo.getComponents()) { for (auto &&n : block) { ks.push_back(i); vs.push_back(n); } ++i; } } inline void BiconnectedComponentsGetComponentOfNode(const BiconnectedComponents &algo, node u, rust::Vec &vs) { for (auto &&n : algo.getComponentsOfNode(u)) { vs.push_back(n); } } inline unique_ptr NewConnectedComponents(const Graph &G) { return make_unique(G); } inline unique_ptr ConnectedComponentsExtractLargestConnectedComponent(const Graph &G, bool compactGraph = false) { return make_unique(ConnectedComponents::extractLargestConnectedComponent(G, compactGraph)); } inline unique_ptr ConnectedComponentsGetPartition(const ConnectedComponents &algo) { return make_unique(algo.getPartition()); } inline void ConnectedComponentsGetComponentSizes(const ConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getComponentSizes()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void ConnectedComponentsGetComponents(const ConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { node i = 0; for (auto &&block : algo.getComponents()) { for (auto &&n : block) { ks.push_back(i); vs.push_back(n); } ++i; } } inline unique_ptr NewDynConnectedComponents(const Graph &G) { return make_unique(G); } inline unique_ptr DynConnectedComponentsGetPartition(const DynConnectedComponents &algo) { return make_unique(algo.getPartition()); } inline void DynConnectedComponentsGetComponentSizes(const DynConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getComponentSizes()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void DynConnectedComponentsGetComponents(const DynConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { node i = 0; for (auto &&block : algo.getComponents()) { for (auto &&n : block) { ks.push_back(i); vs.push_back(n); } ++i; } } inline void DynConnectedComponentsUpdate(DynConnectedComponents &algo, uint8_t kind, node u, node v, edgeweight ew) { algo.update(toGraphEvent(kind, u, v, ew)); } inline void DynConnectedComponentsUpdateBatch(DynConnectedComponents &algo, rust::Slice kinds, rust::Slice us, rust::Slice vs, rust::Slice ews) { vector evs; evs.reserve(kinds.length()); for (size_t i = 0; i < kinds.length(); ++i) { evs.emplace_back(toGraphEvent(kinds[i], us[i], vs[i], ews[i])); } algo.updateBatch(evs); } inline unique_ptr NewDynWeaklyConnectedComponents(const Graph &G) { return make_unique(G); } inline unique_ptr DynWeaklyConnectedComponentsGetPartition(const DynWeaklyConnectedComponents &algo) { return make_unique(algo.getPartition()); } inline void DynWeaklyConnectedComponentsGetComponentSizes(const DynWeaklyConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getComponentSizes()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void DynWeaklyConnectedComponentsGetComponents(const DynWeaklyConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { node i = 0; for (auto &&block : algo.getComponents()) { for (auto &&n : block) { ks.push_back(i); vs.push_back(n); } ++i; } } inline void DynWeaklyConnectedComponentsUpdate(DynWeaklyConnectedComponents &algo, uint8_t kind, node u, node v, edgeweight ew) { algo.update(toGraphEvent(kind, u, v, ew)); } inline void DynWeaklyConnectedComponentsUpdateBatch(DynWeaklyConnectedComponents &algo, rust::Slice kinds, rust::Slice us, rust::Slice vs, rust::Slice ews) { vector evs; evs.reserve(kinds.length()); for (size_t i = 0; i < kinds.length(); ++i) { evs.emplace_back(toGraphEvent(kinds[i], us[i], vs[i], ews[i])); } algo.updateBatch(evs); } inline unique_ptr NewParallelConnectedComponents(const Graph &G, bool coarsening = true) { return make_unique(G, coarsening); } inline unique_ptr ParallelConnectedComponentsGetPartition(const ParallelConnectedComponents &algo) { return make_unique(algo.getPartition()); } inline void ParallelConnectedComponentsGetComponentSizes(const ParallelConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getComponentSizes()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void ParallelConnectedComponentsGetComponents(const ParallelConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { node i = 0; for (auto &&block : algo.getComponents()) { for (auto &&n : block) { ks.push_back(i); vs.push_back(n); } ++i; } } inline unique_ptr NewStronglyConnectedComponents(const Graph &G) { return make_unique(G); } inline unique_ptr StronglyConnectedComponentsGetPartition(const StronglyConnectedComponents &algo) { return make_unique(algo.getPartition()); } inline void StronglyConnectedComponentsGetComponentSizes(const StronglyConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getComponentSizes()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void StronglyConnectedComponentsGetComponents(const StronglyConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { node i = 0; for (auto &&block : algo.getComponents()) { for (auto &&n : block) { ks.push_back(i); vs.push_back(n); } ++i; } } inline unique_ptr NewWeaklyConnectedComponents(const Graph &G) { return make_unique(G); } inline unique_ptr WeaklyConnectedComponentsGetPartition(const WeaklyConnectedComponents &algo) { return make_unique(algo.getPartition()); } inline void WeaklyConnectedComponentsGetComponentSizes(const WeaklyConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getComponentSizes()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void WeaklyConnectedComponentsGetComponents(const WeaklyConnectedComponents &algo, rust::Vec &ks, rust::Vec &vs) { node i = 0; for (auto &&block : algo.getComponents()) { for (auto &&n : block) { ks.push_back(i); vs.push_back(n); } ++i; } } } #endif // NK_COMPONENT_H