Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
57aeeb975acacc9fea1c245d75fe9a6cd5da3f38
[simgrid.git] / src / mc / explo / udpor / EventSet.cpp
1 /* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "src/mc/explo/udpor/EventSet.hpp"
7
8 #include <algorithm>
9 #include <iterator>
10 #include <set>
11
12 namespace simgrid::mc::udpor {
13
14 void EventSet::remove(UnfoldingEvent* e)
15 {
16   this->events_.erase(e);
17 }
18
19 void EventSet::subtract(const EventSet& other)
20 {
21   this->events_ = std::move(subtracting(other).events_);
22 }
23
24 EventSet EventSet::subtracting(const EventSet& other) const
25 {
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));
30 }
31
32 EventSet EventSet::subtracting(UnfoldingEvent* e) const
33 {
34   auto result = this->events_;
35   result.erase(e);
36   return EventSet(std::move(result));
37 }
38
39 void EventSet::insert(UnfoldingEvent* e)
40 {
41   // TODO: Potentially react if the event is already inserted
42   this->events_.insert(e);
43 }
44
45 void EventSet::form_union(const EventSet& other)
46 {
47   this->events_ = std::move(make_union(other).events_);
48 }
49
50 EventSet EventSet::make_union(UnfoldingEvent* e) const
51 {
52   auto result = this->events_;
53   result.insert(e);
54   return EventSet(std::move(result));
55 }
56
57 EventSet EventSet::make_union(const EventSet& other) const
58 {
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));
63 }
64
65 size_t EventSet::size() const
66 {
67   return this->events_.size();
68 }
69
70 bool EventSet::empty() const
71 {
72   return this->events_.empty();
73 }
74
75 bool EventSet::contains(UnfoldingEvent* e) const
76 {
77   return this->events_.find(e) != this->events_.end();
78 }
79
80 bool EventSet::is_subset_of(const EventSet& other) const
81 {
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();
86 }
87
88 } // namespace simgrid::mc::udpor