Refactor: Change reachability interfaces to handle multiple removals/insertions
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user