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

@@ -24,8 +24,11 @@ public:
// in O(1) using the transitive closure matrix
bool query(const T& u, const T& v) override;
// Delete collection of edges
void remove(const std::vector<std::pair<T, T>>& edges) override;
// Delete edge e(u, v) and explicitely maintain the transitive closure
void remove(const T& u, const T& v) override;
void remove(const T& u, const T& v);
private:
// Transitive closure matrix
std::unordered_map<T, std::unordered_map<T, bool>> TC;
@@ -64,6 +67,12 @@ bool Italiano<T>::query(const T& u, const T& v) {
return TC[u][v];
}
template<typename T>
void Italiano<T>::remove(const std::vector<std::pair<T, T>>& edges) {
for (const auto& [u, v] : edges)
remove(u, v);
}
template<typename T>
void Italiano<T>::remove(const T& u, const T& v) {
if (!this->G.adjList[u].contains(v)) return;