]> AND Public Git Repository - simgrid.git/blobdiff - src/mc/explo/udpor/Unfolding.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add operation to plugin doc
[simgrid.git] / src / mc / explo / udpor / Unfolding.cpp
index abe9f26e7e8763bc6564d9715b08f0c49ccfed53..1b63328bbba3b590dcbdd0f34f62a57a747c19b3 100644 (file)
@@ -9,19 +9,26 @@
 
 namespace simgrid::mc::udpor {
 
-void Unfolding::remove(UnfoldingEvent* e)
+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)
 {
-  UnfoldingEvent* handle = e.get();
-  auto loc               = this->global_events_.find(handle);
-  if (loc != this->global_events_.end()) {
+  const UnfoldingEvent* handle = e.get();
+  if (auto loc = this->global_events_.find(handle); loc != this->global_events_.end()) {
     // This is bad: someone wrapped the raw event address twice
     // in two different unique ptrs and attempted to
     // insert it into the unfolding...
@@ -30,7 +37,31 @@ void Unfolding::insert(std::unique_ptr<UnfoldingEvent> e)
   }
 
   // Map the handle to its owner
+  this->event_handles.insert(handle);
   this->global_events_[handle] = std::move(e);
 }
 
+bool Unfolding::contains_event_equivalent_to(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 : *this) {
+    if (*event == *e) {
+      return true;
+    }
+  }
+  return false;
+}
+
+EventSet Unfolding::get_immediate_conflicts_of(const UnfoldingEvent* e) const
+{
+  EventSet immediate_conflicts;
+  for (const auto event : *this) {
+    if (event->immediately_conflicts_with(e)) {
+      immediate_conflicts.insert(e);
+    }
+  }
+  return immediate_conflicts;
+}
+
 } // namespace simgrid::mc::udpor