Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add tests for the Unfolding object
[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 #include "src/mc/explo/udpor/Configuration.hpp"
8
9 #include <iterator>
10
11 namespace simgrid::mc::udpor {
12
13 void EventSet::remove(UnfoldingEvent* e)
14 {
15   this->events_.erase(e);
16 }
17
18 void EventSet::subtract(const EventSet& other)
19 {
20   this->events_ = std::move(subtracting(other).events_);
21 }
22
23 void EventSet::subtract(const Configuration& config)
24 {
25   subtract(config.get_events());
26 }
27
28 EventSet EventSet::subtracting(const EventSet& other) const
29 {
30   std::unordered_set<UnfoldingEvent*> result = this->events_;
31
32   for (UnfoldingEvent* e : other.events_)
33     result.erase(e);
34
35   return EventSet(std::move(result));
36 }
37
38 EventSet EventSet::subtracting(const Configuration& config) const
39 {
40   return subtracting(config.get_events());
41 }
42
43 EventSet EventSet::subtracting(UnfoldingEvent* e) const
44 {
45   auto result = this->events_;
46   result.erase(e);
47   return EventSet(std::move(result));
48 }
49
50 void EventSet::insert(UnfoldingEvent* e)
51 {
52   this->events_.insert(e);
53 }
54
55 void EventSet::form_union(const EventSet& other)
56 {
57   this->events_ = std::move(make_union(other).events_);
58 }
59
60 void EventSet::form_union(const Configuration& config)
61 {
62   form_union(config.get_events());
63 }
64
65 EventSet EventSet::make_union(UnfoldingEvent* e) const
66 {
67   auto result = this->events_;
68   result.insert(e);
69   return EventSet(std::move(result));
70 }
71
72 EventSet EventSet::make_union(const EventSet& other) const
73 {
74   std::unordered_set<UnfoldingEvent*> result = this->events_;
75
76   for (UnfoldingEvent* e : other.events_)
77     result.insert(e);
78
79   return EventSet(std::move(result));
80 }
81
82 EventSet EventSet::make_union(const Configuration& config) const
83 {
84   return make_union(config.get_events());
85 }
86
87 size_t EventSet::size() const
88 {
89   return this->events_.size();
90 }
91
92 bool EventSet::empty() const
93 {
94   return this->events_.empty();
95 }
96
97 bool EventSet::contains(UnfoldingEvent* e) const
98 {
99   return this->events_.find(e) != this->events_.end();
100 }
101
102 bool EventSet::is_subset_of(const EventSet& other) const
103 {
104   // If there is some element not contained in `other`, then
105   // the set difference will contain that element and the
106   // result won't be empty
107   return subtracting(other).empty();
108 }
109
110 } // namespace simgrid::mc::udpor