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/EventSet.hpp"
12 namespace simgrid::mc::udpor {
14 void EventSet::remove(UnfoldingEvent* e)
16 this->events_.erase(e);
19 void EventSet::subtract(const EventSet& other)
21 this->events_ = std::move(subtracting(other).events_);
24 EventSet EventSet::subtracting(const EventSet& other) const
26 std::set<UnfoldingEvent*> result;
27 std::set_difference(this->events_.begin(), this->events_.end(), other.events_.begin(), other.events_.end(),
28 std::inserter(result, result.end()));
29 return EventSet(std::move(result));
32 EventSet EventSet::subtracting(UnfoldingEvent* e) const
34 auto result = this->events_;
36 return EventSet(std::move(result));
39 void EventSet::insert(UnfoldingEvent* e)
41 // TODO: Potentially react if the event is already inserted
42 this->events_.insert(e);
45 void EventSet::form_union(const EventSet& other)
47 this->events_ = std::move(make_union(other).events_);
50 EventSet EventSet::make_union(UnfoldingEvent* e) const
52 auto result = this->events_;
54 return EventSet(std::move(result));
57 EventSet EventSet::make_union(const EventSet& other) const
59 std::set<UnfoldingEvent*> result;
60 std::set_union(this->events_.begin(), this->events_.end(), other.events_.begin(), other.events_.end(),
61 std::inserter(result, result.end()));
62 return EventSet(std::move(result));
65 size_t EventSet::size() const
67 return this->events_.size();
70 bool EventSet::empty() const
72 return this->events_.empty();
75 bool EventSet::contains(UnfoldingEvent* e) const
77 return this->events_.find(e) != this->events_.end();
80 bool EventSet::is_subset_of(const EventSet& other) const
82 // If there is some element not contained in `other`, then
83 // the set difference will contain that element and the
84 // result won't be empty
85 return subtracting(other).empty();
88 } // namespace simgrid::mc::udpor