1 /* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/mc/explo/udpor/Unfolding.hpp"
10 namespace simgrid::mc::udpor {
12 void Unfolding::remove(const EventSet& events)
14 for (const auto e : events) {
19 void Unfolding::remove(const UnfoldingEvent* e)
22 throw std::invalid_argument("Expected a non-null pointer to an event, but received NULL");
24 this->global_events_.erase(e);
25 this->event_handles.remove(e);
28 const UnfoldingEvent* Unfolding::insert(std::unique_ptr<UnfoldingEvent> e)
30 const UnfoldingEvent* handle = e.get();
31 if (auto loc = this->global_events_.find(handle); loc != this->global_events_.end()) {
32 // This is bad: someone wrapped the raw event address twice
33 // in two different unique ptrs and attempted to
34 // insert it into the unfolding...
35 throw std::invalid_argument("Attempted to insert an unfolding event owned twice."
36 "This will result in a double free error and must be fixed.");
39 if (auto loc = this->find_equivalent(handle); loc != this->end()) {
40 // There's already an event in the unfolding that is semantically
41 // equivalent. Return the handle to that event and ignore adding in
46 this->event_handles.insert(handle);
47 this->global_events_[handle] = std::move(e);
51 EventSet Unfolding::get_immediate_conflicts_of(const UnfoldingEvent* e) const
53 EventSet immediate_conflicts;
54 for (const auto event : *this) {
55 if (event->immediately_conflicts_with(e)) {
56 immediate_conflicts.insert(event);
59 return immediate_conflicts;
62 } // namespace simgrid::mc::udpor