Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add dependency between same actor for tests
[simgrid.git] / src / mc / explo / udpor / Unfolding.cpp
index 84ad822cfefc15a14f7b28d34fbeb22193acc8d7..d17274b67f9db08d1760293c0bdd88836d4a24e0 100644 (file)
@@ -9,15 +9,23 @@
 
 namespace simgrid::mc::udpor {
 
+void Unfolding::remove(const EventSet& events)
+{
+  for (const auto e : events) {
+    remove(e);
+  }
+}
+
 void Unfolding::remove(const UnfoldingEvent* e)
 {
   if (e == nullptr) {
     throw std::invalid_argument("Expected a non-null pointer to an event, but received NULL");
   }
   this->global_events_.erase(e);
+  this->event_handles.remove(e);
 }
 
-void Unfolding::insert(std::unique_ptr<UnfoldingEvent> e)
+const UnfoldingEvent* Unfolding::insert(std::unique_ptr<UnfoldingEvent> e)
 {
   const UnfoldingEvent* handle = e.get();
   if (auto loc = this->global_events_.find(handle); loc != this->global_events_.end()) {
@@ -28,20 +36,27 @@ void Unfolding::insert(std::unique_ptr<UnfoldingEvent> e)
                                 "This will result in a  double free error and must be fixed.");
   }
 
-  // Map the handle to its owner
+  if (auto loc = this->find_equivalent(handle); loc != this->end()) {
+    // There's already an event in the unfolding that is semantically
+    // equivalent. Return the handle to that event and ignore adding in
+    // a duplicate event
+    return *loc;
+  }
+
+  this->event_handles.insert(handle);
   this->global_events_[handle] = std::move(e);
+  return handle;
 }
 
-bool Unfolding::contains_event_equivalent_to(const UnfoldingEvent* e) const
+EventSet Unfolding::get_immediate_conflicts_of(const UnfoldingEvent* e) const
 {
-  // Notice the use of `==` equality here. `e` may not be contained in the
-  // unfolding; but some event which is "equivalent" to it could be.
-  for (const auto& [event, _] : global_events_) {
-    if (*event == *e) {
-      return true;
+  EventSet immediate_conflicts;
+  for (const auto event : *this) {
+    if (event->immediately_conflicts_with(e)) {
+      immediate_conflicts.insert(e);
     }
   }
-  return false;
+  return immediate_conflicts;
 }
 
 } // namespace simgrid::mc::udpor