Refactor: Change reachability interfaces to handle multiple removals/insertions

This commit is contained in:
stefiosif
2022-10-15 10:40:08 +03:00
parent 04ab33888e
commit e7fd88f82c
8 changed files with 41 additions and 37 deletions

View File

@@ -25,8 +25,11 @@ public:
// Return true if u and v are in the same SCC
bool query(const T& u, const T& v) override;
// Delete collection of edges
void remove(const std::vector<std::pair<T, T>>& edges) override;
// Remove edge (u,v) and update A accordingly for fast checking query
void remove(const T& u, const T& v) override;
void remove(const T& u, const T& v);
std::unordered_map<T, SCC<T>> getSCCs() { return C; }
private:
@@ -68,6 +71,12 @@ bool RodittyZwick<T>::query(const T& u, const T& v) {
return A[u] == A[v];
}
template<typename T>
void RodittyZwick<T>::remove(const std::vector<std::pair<T, T>>& edges) {
for (const auto& [u, v] : edges)
remove(u, v);
}
template<typename T>
void RodittyZwick<T>::remove(const T& u, const T& v) {
const auto& w = A[u];